1792 gear^.aihints:= lua_tointeger(L, 2); |
1794 gear^.aihints:= lua_tointeger(L, 2); |
1793 end; |
1795 end; |
1794 lc_setaihintsongear:= 0 |
1796 lc_setaihintsongear:= 0 |
1795 end; |
1797 end; |
1796 |
1798 |
|
1799 |
|
1800 function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl; |
|
1801 begin |
|
1802 if lua_gettop(L) <> 1 then |
|
1803 begin |
|
1804 LuaError('Lua: Wrong number of parameters passed to HedgewarsScriptLoad!'); |
|
1805 lua_pushnil(L) |
|
1806 end |
|
1807 else |
|
1808 ScriptLoad(lua_tostring(L, 1)); |
|
1809 lc_hedgewarsscriptload:= 0; |
|
1810 end; |
1797 /////////////////// |
1811 /////////////////// |
1798 |
1812 |
1799 procedure ScriptPrintStack; |
1813 procedure ScriptPrintStack; |
1800 var n, i : LongInt; |
1814 var n, i : LongInt; |
1801 begin |
1815 begin |
1964 ScriptSetInteger('ScreenHeight', cScreenHeight); |
1978 ScriptSetInteger('ScreenHeight', cScreenHeight); |
1965 ScriptSetInteger('ScreenWidth', cScreenWidth); |
1979 ScriptSetInteger('ScreenWidth', cScreenWidth); |
1966 ScriptCall('onScreenResize'); |
1980 ScriptCall('onScreenResize'); |
1967 end; |
1981 end; |
1968 |
1982 |
|
1983 // custom script loader via physfs, passed to lua_load |
|
1984 const BUFSIZE = 1024; |
1969 |
1985 |
1970 procedure ScriptLoad(name : shortstring); |
1986 procedure ScriptLoad(name : shortstring); |
1971 var ret : LongInt; |
1987 var ret : LongInt; |
1972 s : shortstring; |
1988 s : shortstring; |
1973 begin |
1989 f : PFSFile; |
1974 s:= UserPathz[ptData] + '/' + name; |
1990 buf : array[0..Pred(BUFSIZE)] of byte; |
1975 if not FileExists(s) then |
1991 begin |
1976 s:= Pathz[ptData] + '/' + name; |
1992 s:= cPathz[ptData] + name; |
1977 if not FileExists(s) then |
1993 if not pfsExists(s) then |
1978 exit; |
1994 exit; |
1979 |
1995 |
1980 ret:= luaL_loadfile(luaState, Str2PChar(s)); |
1996 f:= pfsOpenRead(s); |
|
1997 if f = nil then |
|
1998 exit; |
|
1999 |
|
2000 physfsReaderSetBuffer(@buf); |
|
2001 ret:= lua_load(luaState, @physfsReader, f, Str2PChar(s)); |
|
2002 pfsClose(f); |
|
2003 |
1981 if ret <> 0 then |
2004 if ret <> 0 then |
1982 begin |
2005 begin |
1983 LuaError('Lua: Failed to load ' + name + '(error ' + IntToStr(ret) + ')'); |
2006 LuaError('Lua: Failed to load ' + name + '(error ' + IntToStr(ret) + ')'); |
1984 LuaError('Lua: ' + lua_tostring(luaState, -1)); |
2007 LuaError('Lua: ' + lua_tostring(luaState, -1)); |
1985 end |
2008 end |
2393 lua_register(luaState, _P'PlaceGirder', @lc_placegirder); |
2416 lua_register(luaState, _P'PlaceGirder', @lc_placegirder); |
2394 lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype); |
2417 lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype); |
2395 lua_register(luaState, _P'TestRectForObstacle', @lc_testrectforobstacle); |
2418 lua_register(luaState, _P'TestRectForObstacle', @lc_testrectforobstacle); |
2396 |
2419 |
2397 lua_register(luaState, _P'SetGearAIHints', @lc_setaihintsongear); |
2420 lua_register(luaState, _P'SetGearAIHints', @lc_setaihintsongear); |
|
2421 lua_register(luaState, _P'HedgewarsScriptLoad', @lc_hedgewarsscriptload); |
2398 |
2422 |
2399 |
2423 |
2400 ScriptClearStack; // just to be sure stack is empty |
2424 ScriptClearStack; // just to be sure stack is empty |
2401 ScriptLoaded:= false; |
2425 ScriptLoaded:= false; |
2402 end; |
2426 end; |