hedgewars/uScript.pas
changeset 13729 a62408ee8281
parent 13726 61095cb5f58a
child 13730 eeeea1cfaf08
equal deleted inserted replaced
13728:ade61b4eb63f 13729:a62408ee8281
    32 interface
    32 interface
    33 
    33 
    34 procedure ScriptPrintStack;
    34 procedure ScriptPrintStack;
    35 procedure ScriptClearStack;
    35 procedure ScriptClearStack;
    36 
    36 
    37 procedure ScriptLoad(name : shortstring; mustExist : boolean);
    37 function  ScriptLoad(name : shortstring; mustExist : boolean) : boolean;
    38 procedure ScriptOnPreviewInit;
    38 procedure ScriptOnPreviewInit;
    39 procedure ScriptOnGameInit;
    39 procedure ScriptOnGameInit;
    40 procedure ScriptOnScreenResize;
    40 procedure ScriptOnScreenResize;
    41 procedure ScriptSetInteger(name : shortstring; value : LongInt);
    41 procedure ScriptSetInteger(name : shortstring; value : LongInt);
    42 procedure ScriptSetString(name : shortstring; value : shortstring);
    42 procedure ScriptSetString(name : shortstring; value : shortstring);
  3064     lc_setgearaihints:= 0
  3064     lc_setgearaihints:= 0
  3065 end;
  3065 end;
  3066 
  3066 
  3067 
  3067 
  3068 function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl;
  3068 function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl;
       
  3069 var success : boolean;
  3069 begin
  3070 begin
  3070     if CheckLuaParamCount(L, 1, 'HedgewarsScriptLoad', 'scriptPath') then
  3071     if CheckLuaParamCount(L, 1, 'HedgewarsScriptLoad', 'scriptPath') then
  3071         ScriptLoad(lua_tostring(L, 1), true)
  3072         begin
  3072     else
  3073         success:= ScriptLoad(lua_tostring(L, 1), false);
  3073         lua_pushnil(L);
  3074         lua_pushboolean(L, success);
  3074     lc_hedgewarsscriptload:= 0;
  3075         end
       
  3076     else
       
  3077         lua_pushboolean(L, false);
       
  3078     lc_hedgewarsscriptload:= 1;
  3075 end;
  3079 end;
  3076 
  3080 
  3077 
  3081 
  3078 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl;
  3082 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl;
  3079 begin
  3083 begin
  3558         end;
  3562         end;
  3559     ScriptLocaleReader:= mybuf
  3563     ScriptLocaleReader:= mybuf
  3560 end;
  3564 end;
  3561 // ⭒⭐⭒✨⭐⭒✨⭐☆✨⭐✨✧✨☆✨✧✨☆⭒✨☆⭐⭒☆✧✨⭒✨⭐✧⭒☆⭒✧☆✨✧⭐☆✨☆✧⭒✨✧⭒☆⭐☆✧
  3565 // ⭒⭐⭒✨⭐⭒✨⭐☆✨⭐✨✧✨☆✨✧✨☆⭒✨☆⭐⭒☆✧✨⭒✨⭐✧⭒☆⭒✧☆✨✧⭐☆✨☆✧⭒✨✧⭒☆⭐☆✧
  3562 
  3566 
  3563 procedure ScriptLoad(name : shortstring; mustExist : boolean);
  3567 function ScriptLoad(name : shortstring; mustExist : boolean) : boolean;
  3564 var ret : LongInt;
  3568 var ret : LongInt;
  3565       s : shortstring;
  3569       s : shortstring;
  3566       f : PFSFile;
  3570       f : PFSFile;
  3567     buf : array[0..Pred(BUFSIZE)] of byte;
  3571     buf : array[0..Pred(BUFSIZE)] of byte;
  3568 begin
  3572 begin
  3577     begin
  3581     begin
  3578     if mustExist then
  3582     if mustExist then
  3579         OutError('Script not found: ' + name, true)
  3583         OutError('Script not found: ' + name, true)
  3580     else
  3584     else
  3581         AddFileLog('[LUA] Script not found: ' + name);
  3585         AddFileLog('[LUA] Script not found: ' + name);
       
  3586     ScriptLoad:= false;
  3582     exit;
  3587     exit;
  3583     end;
  3588     end;
  3584 
  3589 
  3585 f:= pfsOpenRead(s);
  3590 f:= pfsOpenRead(s);
  3586 if f = nil then
  3591 if f = nil then
  3600 
  3605 
  3601 if ret <> 0 then
  3606 if ret <> 0 then
  3602     begin
  3607     begin
  3603     LuaError('Failed to load ' + name + '(error ' + IntToStr(ret) + ')');
  3608     LuaError('Failed to load ' + name + '(error ' + IntToStr(ret) + ')');
  3604     LuaError(lua_tostring(luaState, -1));
  3609     LuaError(lua_tostring(luaState, -1));
       
  3610     ScriptLoad:= false;
  3605     end
  3611     end
  3606 else
  3612 else
  3607     begin
  3613     begin
  3608     WriteLnToConsole('Lua: ' + name + ' loaded');
  3614     WriteLnToConsole('Lua: ' + name + ' loaded');
  3609     // call the script file
  3615     // call the script file
  3610     lua_pcall(luaState, 0, 0, 0);
  3616     lua_pcall(luaState, 0, 0, 0);
  3611     ScriptLoaded:= true
  3617     ScriptLoaded:= true;
       
  3618     ScriptLoad:= true;
  3612     end;
  3619     end;
  3613 end;
  3620 end;
  3614 
  3621 
  3615 procedure SetGlobals;
  3622 procedure SetGlobals;
  3616 var x, y: LongInt;
  3623 var x, y: LongInt;