equal
deleted
inserted
replaced
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 begin |
3069 var success : boolean; |
3070 if CheckLuaParamCount(L, 1, 'HedgewarsScriptLoad', 'scriptPath') then |
3070 n : LongInt; |
3071 ScriptLoad(lua_tostring(L, 1), true) |
3071 begin |
3072 else |
3072 if CheckAndFetchParamCount(L, 1, 2, 'HedgewarsScriptLoad', 'scriptPath [, mustExist]', n) then |
3073 lua_pushnil(L); |
3073 begin |
3074 lc_hedgewarsscriptload:= 0; |
3074 if n = 1 then |
|
3075 success:= ScriptLoad(lua_tostring(L, 1), true) |
|
3076 else |
|
3077 success:= ScriptLoad(lua_tostring(L, 1), lua_toboolean(L, 2)); |
|
3078 end |
|
3079 else |
|
3080 success:= false; |
|
3081 lua_pushboolean(L, success); |
|
3082 lc_hedgewarsscriptload:= 1; |
3075 end; |
3083 end; |
3076 |
3084 |
3077 |
3085 |
3078 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl; |
3086 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl; |
3079 begin |
3087 begin |
3558 end; |
3566 end; |
3559 ScriptLocaleReader:= mybuf |
3567 ScriptLocaleReader:= mybuf |
3560 end; |
3568 end; |
3561 // ⭒⭐⭒✨⭐⭒✨⭐☆✨⭐✨✧✨☆✨✧✨☆⭒✨☆⭐⭒☆✧✨⭒✨⭐✧⭒☆⭒✧☆✨✧⭐☆✨☆✧⭒✨✧⭒☆⭐☆✧ |
3569 // ⭒⭐⭒✨⭐⭒✨⭐☆✨⭐✨✧✨☆✨✧✨☆⭒✨☆⭐⭒☆✧✨⭒✨⭐✧⭒☆⭒✧☆✨✧⭐☆✨☆✧⭒✨✧⭒☆⭐☆✧ |
3562 |
3570 |
3563 procedure ScriptLoad(name : shortstring; mustExist : boolean); |
3571 function ScriptLoad(name : shortstring; mustExist : boolean): boolean; |
3564 var ret : LongInt; |
3572 var ret : LongInt; |
3565 s : shortstring; |
3573 s : shortstring; |
3566 f : PFSFile; |
3574 f : PFSFile; |
3567 buf : array[0..Pred(BUFSIZE)] of byte; |
3575 buf : array[0..Pred(BUFSIZE)] of byte; |
3568 begin |
3576 begin |
3577 begin |
3585 begin |
3578 if mustExist then |
3586 if mustExist then |
3579 OutError('Script not found: ' + name, true) |
3587 OutError('Script not found: ' + name, true) |
3580 else |
3588 else |
3581 AddFileLog('[LUA] Script not found: ' + name); |
3589 AddFileLog('[LUA] Script not found: ' + name); |
|
3590 ScriptLoad:= false; |
3582 exit; |
3591 exit; |
3583 end; |
3592 end; |
3584 |
3593 |
3585 f:= pfsOpenRead(s); |
3594 f:= pfsOpenRead(s); |
3586 if f = nil then |
3595 if f = nil then |
3600 |
3609 |
3601 if ret <> 0 then |
3610 if ret <> 0 then |
3602 begin |
3611 begin |
3603 LuaError('Failed to load ' + name + '(error ' + IntToStr(ret) + ')'); |
3612 LuaError('Failed to load ' + name + '(error ' + IntToStr(ret) + ')'); |
3604 LuaError(lua_tostring(luaState, -1)); |
3613 LuaError(lua_tostring(luaState, -1)); |
|
3614 ScriptLoad:= false; |
3605 end |
3615 end |
3606 else |
3616 else |
3607 begin |
3617 begin |
3608 WriteLnToConsole('Lua: ' + name + ' loaded'); |
3618 WriteLnToConsole('Lua: ' + name + ' loaded'); |
3609 // call the script file |
3619 // call the script file |
3610 lua_pcall(luaState, 0, 0, 0); |
3620 lua_pcall(luaState, 0, 0, 0); |
3611 ScriptLoaded:= true |
3621 ScriptLoaded:= true; |
|
3622 ScriptLoad:= true; |
3612 end; |
3623 end; |
3613 end; |
3624 end; |
3614 |
3625 |
3615 procedure SetGlobals; |
3626 procedure SetGlobals; |
3616 var x, y: LongInt; |
3627 var x, y: LongInt; |