hedgewars/uScript.pas
changeset 3539 c3d1fccbe0ed
parent 3407 dcc129c4352e
child 3697 d5b30d6373fc
equal deleted inserted replaced
3537:8f5b3108f29c 3539:c3d1fccbe0ed
    48     uFloat,
    48     uFloat,
    49     uWorld,
    49     uWorld,
    50     uAmmos,
    50     uAmmos,
    51     uSound,
    51     uSound,
    52     uTeams,
    52     uTeams,
    53     uKeys;
    53     uKeys,
       
    54     uChat;
    54     
    55     
    55 var luaState : Plua_State;
    56 var luaState : Plua_State;
    56     ScriptAmmoLoadout : shortstring;
    57     ScriptAmmoLoadout : shortstring;
    57     ScriptAmmoProbability : shortstring;
    58     ScriptAmmoProbability : shortstring;
    58     ScriptAmmoDelay : shortstring;
    59     ScriptAmmoDelay : shortstring;
    61     
    62     
    62 procedure ScriptPrepareAmmoStore; forward;
    63 procedure ScriptPrepareAmmoStore; forward;
    63 procedure ScriptApplyAmmoStore; forward;
    64 procedure ScriptApplyAmmoStore; forward;
    64 procedure ScriptSetAmmo(ammo : TAmmoType; count, propability, delay, reinforcement: Byte); forward;
    65 procedure ScriptSetAmmo(ammo : TAmmoType; count, propability, delay, reinforcement: Byte); forward;
    65 
    66 
       
    67 procedure LuaError(s: shortstring);
       
    68 begin
       
    69     WriteLnToConsole(s);
       
    70     AddChatString(#5 + s);
       
    71 end;
       
    72 
    66 // wrapped calls //
    73 // wrapped calls //
    67 
    74 
    68 // functions called from lua:
    75 // functions called from Lua:
    69 // function(L : Plua_State) : LongInt; Cdecl;
    76 // function(L : Plua_State) : LongInt; Cdecl;
    70 // where L contains the state, returns the number of return values on the stack
    77 // where L contains the state, returns the number of return values on the stack
    71 // call lua_gettop(L) to receive number of parameters passed
    78 // call lua_gettop(L) to receive number of parameters passed
    72 
    79 
    73 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl;
    80 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl;
    74 begin
    81 begin
    75     if lua_gettop(L) = 1 then
    82     if lua_gettop(L) = 1 then
    76         begin
    83         begin
    77         WriteLnToConsole('LUA: ' + lua_tostring(L ,1));
    84         WriteLnToConsole('Lua: ' + lua_tostring(L ,1));
    78         end
    85         end
    79     else
    86     else
    80         WriteLnToConsole('LUA: Wrong number of parameters passed to WriteLnToConsole!');
    87         LuaError('Lua: Wrong number of parameters passed to WriteLnToConsole!');
    81     lc_writelntoconsole:= 0;
    88     lc_writelntoconsole:= 0;
    82 end;
    89 end;
    83 
    90 
    84 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl;
    91 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl;
    85 begin
    92 begin
    86     if lua_gettop(L) = 1 then
    93     if lua_gettop(L) = 1 then
    87         begin
    94         begin
    88         ParseCommand(lua_tostring(L ,1), true);
    95         ParseCommand(lua_tostring(L ,1), true);
    89         end
    96         end
    90     else
    97     else
    91         WriteLnToConsole('LUA: Wrong number of parameters passed to ParseCommand!');
    98         LuaError('Lua: Wrong number of parameters passed to ParseCommand!');
    92     lc_parsecommand:= 0;
    99     lc_parsecommand:= 0;
    93 end;
   100 end;
    94 
   101 
    95 function lc_showmission(L : Plua_State) : LongInt; Cdecl;
   102 function lc_showmission(L : Plua_State) : LongInt; Cdecl;
    96 begin
   103 begin
    97     if lua_gettop(L) = 5 then
   104     if lua_gettop(L) = 5 then
    98         begin
   105         begin
    99         ShowMission(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
   106         ShowMission(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
   100         end
   107         end
   101     else
   108     else
   102         WriteLnToConsole('LUA: Wrong number of parameters passed to ShowMission!');
   109         LuaError('Lua: Wrong number of parameters passed to ShowMission!');
   103     lc_showmission:= 0;
   110     lc_showmission:= 0;
   104 end;
   111 end;
   105 
   112 
   106 function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
   113 function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
   107 begin
   114 begin
   116     dx, dy: hwFloat;
   123     dx, dy: hwFloat;
   117     gt: TGearType;
   124     gt: TGearType;
   118 begin
   125 begin
   119     if lua_gettop(L) <> 7 then
   126     if lua_gettop(L) <> 7 then
   120         begin
   127         begin
   121         WriteLnToConsole('LUA: Wrong number of parameters passed to AddGear!');
   128         LuaError('Lua: Wrong number of parameters passed to AddGear!');
   122         lua_pushnil(L); // return value on stack (nil)
   129         lua_pushnil(L); // return value on stack (nil)
   123         end
   130         end
   124     else
   131     else
   125         begin
   132         begin
   126         x:= lua_tointeger(L, 1);
   133         x:= lua_tointeger(L, 1);
   139 
   146 
   140 function lc_getfollowgear(L : Plua_State) : LongInt; Cdecl;
   147 function lc_getfollowgear(L : Plua_State) : LongInt; Cdecl;
   141 begin
   148 begin
   142     if lua_gettop(L) <> 0 then
   149     if lua_gettop(L) <> 0 then
   143         begin
   150         begin
   144         WriteLnToConsole('LUA: Wrong number of parameters passed to GetFollowGear!');
   151         LuaError('Lua: Wrong number of parameters passed to GetFollowGear!');
   145         lua_pushnil(L); // return value on stack (nil)
   152         lua_pushnil(L); // return value on stack (nil)
   146         end
   153         end
   147     else
   154     else
   148         if FollowGear = nil then
   155         if FollowGear = nil then
   149             lua_pushnil(L)
   156             lua_pushnil(L)
   155 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl;
   162 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl;
   156 var gear : PGear;
   163 var gear : PGear;
   157 begin
   164 begin
   158     if lua_gettop(L) <> 1 then
   165     if lua_gettop(L) <> 1 then
   159         begin
   166         begin
   160         WriteLnToConsole('LUA: Wrong number of parameters passed to GetGearType!');
   167         LuaError('Lua: Wrong number of parameters passed to GetGearType!');
   161         lua_pushnil(L); // return value on stack (nil)
   168         lua_pushnil(L); // return value on stack (nil)
   162         end
   169         end
   163     else
   170     else
   164         begin
   171         begin
   165         gear:= GearByUID(lua_tointeger(L, 1));
   172         gear:= GearByUID(lua_tointeger(L, 1));
   174 function lc_gethogclan(L : Plua_State) : LongInt; Cdecl;
   181 function lc_gethogclan(L : Plua_State) : LongInt; Cdecl;
   175 var gear : PGear;
   182 var gear : PGear;
   176 begin
   183 begin
   177     if lua_gettop(L) <> 1 then
   184     if lua_gettop(L) <> 1 then
   178         begin
   185         begin
   179         WriteLnToConsole('LUA: Wrong number of parameters passed to GetHogClan!');
   186         LuaError('Lua: Wrong number of parameters passed to GetHogClan!');
   180         lua_pushnil(L); // return value on stack (nil)
   187         lua_pushnil(L); // return value on stack (nil)
   181         end
   188         end
   182     else
   189     else
   183         begin
   190         begin
   184         gear:= GearByUID(lua_tointeger(L, 1));
   191         gear:= GearByUID(lua_tointeger(L, 1));
   195 function lc_gethogname(L : Plua_State) : LongInt; Cdecl;
   202 function lc_gethogname(L : Plua_State) : LongInt; Cdecl;
   196 var gear : PGear;
   203 var gear : PGear;
   197 begin
   204 begin
   198     if lua_gettop(L) <> 1 then
   205     if lua_gettop(L) <> 1 then
   199         begin
   206         begin
   200         WriteLnToConsole('LUA: Wrong number of parameters passed to GetHogName!');
   207         LuaError('Lua: Wrong number of parameters passed to GetHogName!');
   201         lua_pushnil(L); // return value on stack (nil)
   208         lua_pushnil(L); // return value on stack (nil)
   202         end
   209         end
   203     else
   210     else
   204         begin
   211         begin
   205         gear:= GearByUID(lua_tointeger(L, 1));
   212         gear:= GearByUID(lua_tointeger(L, 1));
   216 function lc_getx(L : Plua_State) : LongInt; Cdecl;
   223 function lc_getx(L : Plua_State) : LongInt; Cdecl;
   217 var gear : PGear;
   224 var gear : PGear;
   218 begin
   225 begin
   219     if lua_gettop(L) <> 1 then
   226     if lua_gettop(L) <> 1 then
   220         begin
   227         begin
   221         WriteLnToConsole('LUA: Wrong number of parameters passed to GetX!');
   228         LuaError('Lua: Wrong number of parameters passed to GetX!');
   222         lua_pushnil(L); // return value on stack (nil)
   229         lua_pushnil(L); // return value on stack (nil)
   223         end
   230         end
   224     else
   231     else
   225         begin
   232         begin
   226         gear:= GearByUID(lua_tointeger(L, 1));
   233         gear:= GearByUID(lua_tointeger(L, 1));
   235 function lc_gety(L : Plua_State) : LongInt; Cdecl;
   242 function lc_gety(L : Plua_State) : LongInt; Cdecl;
   236 var gear : PGear;
   243 var gear : PGear;
   237 begin
   244 begin
   238     if lua_gettop(L) <> 1 then
   245     if lua_gettop(L) <> 1 then
   239         begin
   246         begin
   240         WriteLnToConsole('LUA: Wrong number of parameters passed to GetY!');
   247         LuaError('Lua: Wrong number of parameters passed to GetY!');
   241         lua_pushnil(L); // return value on stack (nil)
   248         lua_pushnil(L); // return value on stack (nil)
   242         end
   249         end
   243     else
   250     else
   244         begin
   251         begin
   245         gear:= GearByUID(lua_tointeger(L, 1));
   252         gear:= GearByUID(lua_tointeger(L, 1));
   254 function lc_copypv(L : Plua_State) : LongInt; Cdecl;
   261 function lc_copypv(L : Plua_State) : LongInt; Cdecl;
   255 var gears, geard : PGear;
   262 var gears, geard : PGear;
   256 begin
   263 begin
   257     if lua_gettop(L) <> 2 then
   264     if lua_gettop(L) <> 2 then
   258         begin
   265         begin
   259         WriteLnToConsole('LUA: Wrong number of parameters passed to CopyPV!');
   266         LuaError('Lua: Wrong number of parameters passed to CopyPV!');
   260         end
   267         end
   261     else
   268     else
   262         begin
   269         begin
   263         gears:= GearByUID(lua_tointeger(L, 1));
   270         gears:= GearByUID(lua_tointeger(L, 1));
   264         geard:= GearByUID(lua_tointeger(L, 2));
   271         geard:= GearByUID(lua_tointeger(L, 2));
   276 function lc_copypv2(L : Plua_State) : LongInt; Cdecl;
   283 function lc_copypv2(L : Plua_State) : LongInt; Cdecl;
   277 var gears, geard : PGear;
   284 var gears, geard : PGear;
   278 begin
   285 begin
   279     if lua_gettop(L) <> 2 then
   286     if lua_gettop(L) <> 2 then
   280         begin
   287         begin
   281         WriteLnToConsole('LUA: Wrong number of parameters passed to CopyPV2!');
   288         LuaError('Lua: Wrong number of parameters passed to CopyPV2!');
   282         end
   289         end
   283     else
   290     else
   284         begin
   291         begin
   285         gears:= GearByUID(lua_tointeger(L, 1));
   292         gears:= GearByUID(lua_tointeger(L, 1));
   286         geard:= GearByUID(lua_tointeger(L, 2));
   293         geard:= GearByUID(lua_tointeger(L, 2));
   297 
   304 
   298 function lc_followgear(L : Plua_State) : LongInt; Cdecl;
   305 function lc_followgear(L : Plua_State) : LongInt; Cdecl;
   299 var gear : PGear;
   306 var gear : PGear;
   300 begin
   307 begin
   301     if lua_gettop(L) <> 1 then
   308     if lua_gettop(L) <> 1 then
   302         WriteLnToConsole('LUA: Wrong number of parameters passed to FollowGear!')
   309         LuaError('Lua: Wrong number of parameters passed to FollowGear!')
   303     else
   310     else
   304         begin
   311         begin
   305         gear:= GearByUID(lua_tointeger(L, 1));
   312         gear:= GearByUID(lua_tointeger(L, 1));
   306         if gear <> nil then FollowGear:= gear
   313         if gear <> nil then FollowGear:= gear
   307         end;
   314         end;
   311 function lc_sethealth(L : Plua_State) : LongInt; Cdecl;
   318 function lc_sethealth(L : Plua_State) : LongInt; Cdecl;
   312 var gear : PGear;
   319 var gear : PGear;
   313 begin
   320 begin
   314     if lua_gettop(L) <> 2 then
   321     if lua_gettop(L) <> 2 then
   315         begin
   322         begin
   316         WriteLnToConsole('LUA: Wrong number of parameters passed to SetHealth!');
   323         LuaError('Lua: Wrong number of parameters passed to SetHealth!');
   317         end
   324         end
   318     else
   325     else
   319         begin
   326         begin
   320         gear:= GearByUID(lua_tointeger(L, 1));
   327         gear:= GearByUID(lua_tointeger(L, 1));
   321         if gear <> nil then gear^.Health:= lua_tointeger(L, 2)
   328         if gear <> nil then gear^.Health:= lua_tointeger(L, 2)
   326 function lc_setstate(L : Plua_State) : LongInt; Cdecl;
   333 function lc_setstate(L : Plua_State) : LongInt; Cdecl;
   327 var gear : PGear;
   334 var gear : PGear;
   328 begin
   335 begin
   329     if lua_gettop(L) <> 2 then
   336     if lua_gettop(L) <> 2 then
   330         begin
   337         begin
   331         WriteLnToConsole('LUA: Wrong number of parameters passed to SetState!');
   338         LuaError('Lua: Wrong number of parameters passed to SetState!');
   332         end
   339         end
   333     else
   340     else
   334         begin
   341         begin
   335         gear:= GearByUID(lua_tointeger(L, 1));
   342         gear:= GearByUID(lua_tointeger(L, 1));
   336         if gear <> nil then gear^.State:= lua_tointeger(L, 2)
   343         if gear <> nil then gear^.State:= lua_tointeger(L, 2)
   341 function lc_getstate(L : Plua_State) : LongInt; Cdecl;
   348 function lc_getstate(L : Plua_State) : LongInt; Cdecl;
   342 var gear : PGear;
   349 var gear : PGear;
   343 begin
   350 begin
   344     if lua_gettop(L) <> 1 then
   351     if lua_gettop(L) <> 1 then
   345         begin
   352         begin
   346         WriteLnToConsole('LUA: Wrong number of parameters passed to GetState!');
   353         LuaError('Lua: Wrong number of parameters passed to GetState!');
   347         end
   354         end
   348     else
   355     else
   349         begin
   356         begin
   350         gear:= GearByUID(lua_tointeger(L, 1));
   357         gear:= GearByUID(lua_tointeger(L, 1));
   351         if gear <> nil then
   358         if gear <> nil then
   359 function lc_settag(L : Plua_State) : LongInt; Cdecl;
   366 function lc_settag(L : Plua_State) : LongInt; Cdecl;
   360 var gear : PGear;
   367 var gear : PGear;
   361 begin
   368 begin
   362     if lua_gettop(L) <> 2 then
   369     if lua_gettop(L) <> 2 then
   363         begin
   370         begin
   364         WriteLnToConsole('LUA: Wrong number of parameters passed to SetTag!');
   371         LuaError('Lua: Wrong number of parameters passed to SetTag!');
   365         end
   372         end
   366     else
   373     else
   367         begin
   374         begin
   368         gear:= GearByUID(lua_tointeger(L, 1));
   375         gear:= GearByUID(lua_tointeger(L, 1));
   369         if gear <> nil then gear^.Tag:= lua_tointeger(L, 2)
   376         if gear <> nil then gear^.Tag:= lua_tointeger(L, 2)
   382 var gear: PGear;
   389 var gear: PGear;
   383     fall: boolean;
   390     fall: boolean;
   384     left, right: LongInt;
   391     left, right: LongInt;
   385 begin
   392 begin
   386     if lua_gettop(L) <> 4 then
   393     if lua_gettop(L) <> 4 then
   387         WriteLnToConsole('LUA: Wrong number of parameters passed to FindPlace!')
   394         LuaError('Lua: Wrong number of parameters passed to FindPlace!')
   388     else
   395     else
   389         begin
   396         begin
   390         gear:= GearByUID(lua_tointeger(L, 1));
   397         gear:= GearByUID(lua_tointeger(L, 1));
   391         fall:= lua_toboolean(L, 2);
   398         fall:= lua_toboolean(L, 2);
   392         left:= lua_tointeger(L, 3);
   399         left:= lua_tointeger(L, 3);
   398 end;
   405 end;
   399 
   406 
   400 function lc_playsound(L : Plua_State) : LongInt; Cdecl;
   407 function lc_playsound(L : Plua_State) : LongInt; Cdecl;
   401 begin
   408 begin
   402     if lua_gettop(L) <> 1 then
   409     if lua_gettop(L) <> 1 then
   403         WriteLnToConsole('LUA: Wrong number of parameters passed to PlaySound!')
   410         LuaError('Lua: Wrong number of parameters passed to PlaySound!')
   404     else
   411     else
   405         PlaySound(TSound(lua_tointeger(L, 1)));
   412         PlaySound(TSound(lua_tointeger(L, 1)));
   406     lc_playsound:= 0;
   413     lc_playsound:= 0;
   407 end;
   414 end;
   408 
   415 
   409 function lc_addteam(L : Plua_State) : LongInt; Cdecl;
   416 function lc_addteam(L : Plua_State) : LongInt; Cdecl;
   410 begin
   417 begin
   411     if lua_gettop(L) <> 5 then
   418     if lua_gettop(L) <> 5 then
   412         begin
   419         begin
   413         WriteLnToConsole('LUA: Wrong number of parameters passed to AddTeam!');
   420         LuaError('Lua: Wrong number of parameters passed to AddTeam!');
   414         //lua_pushnil(L)
   421         //lua_pushnil(L)
   415         end
   422         end
   416     else
   423     else
   417         begin
   424         begin
   418         ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true);
   425         ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true);
   429 function lc_addhog(L : Plua_State) : LongInt; Cdecl;
   436 function lc_addhog(L : Plua_State) : LongInt; Cdecl;
   430 var temp: ShortString;
   437 var temp: ShortString;
   431 begin
   438 begin
   432     if lua_gettop(L) <> 4 then
   439     if lua_gettop(L) <> 4 then
   433         begin
   440         begin
   434         WriteLnToConsole('LUA: Wrong number of parameters passed to AddHog!');
   441         LuaError('Lua: Wrong number of parameters passed to AddHog!');
   435         lua_pushnil(L)
   442         lua_pushnil(L)
   436         end
   443         end
   437     else
   444     else
   438         begin
   445         begin
   439         temp:= lua_tostring(L, 4);
   446         temp:= lua_tostring(L, 4);
   447 function lc_getgearposition(L : Plua_State) : LongInt; Cdecl;
   454 function lc_getgearposition(L : Plua_State) : LongInt; Cdecl;
   448 var gear: PGear;
   455 var gear: PGear;
   449 begin
   456 begin
   450     if lua_gettop(L) <> 1 then
   457     if lua_gettop(L) <> 1 then
   451         begin
   458         begin
   452         WriteLnToConsole('LUA: Wrong number of parameters passed to GetGearPosition!');
   459         LuaError('Lua: Wrong number of parameters passed to GetGearPosition!');
   453         lua_pushnil(L);
   460         lua_pushnil(L);
   454         lua_pushnil(L)
   461         lua_pushnil(L)
   455         end
   462         end
   456     else
   463     else
   457         begin
   464         begin
   468 function lc_setgearposition(L : Plua_State) : LongInt; Cdecl;
   475 function lc_setgearposition(L : Plua_State) : LongInt; Cdecl;
   469 var gear: PGear;
   476 var gear: PGear;
   470     x, y: LongInt;
   477     x, y: LongInt;
   471 begin
   478 begin
   472     if lua_gettop(L) <> 3 then
   479     if lua_gettop(L) <> 3 then
   473         WriteLnToConsole('LUA: Wrong number of parameters passed to SetGearPosition!')
   480         LuaError('Lua: Wrong number of parameters passed to SetGearPosition!')
   474     else
   481     else
   475         begin
   482         begin
   476         gear:= GearByUID(lua_tointeger(L, 1));
   483         gear:= GearByUID(lua_tointeger(L, 1));
   477         if gear <> nil then
   484         if gear <> nil then
   478             begin
   485             begin
   488 function lc_setammo(L : Plua_State) : LongInt; Cdecl;
   495 function lc_setammo(L : Plua_State) : LongInt; Cdecl;
   489 var np: LongInt;
   496 var np: LongInt;
   490 begin
   497 begin
   491     np:= lua_gettop(L);
   498     np:= lua_gettop(L);
   492     if (np < 4) or (np > 5) then
   499     if (np < 4) or (np > 5) then
   493         WriteLnToConsole('LUA: Wrong number of parameters passed to SetAmmo!')
   500         LuaError('Lua: Wrong number of parameters passed to SetAmmo!')
   494     else if np = 4 then
   501     else if np = 4 then
   495         ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), 1)
   502         ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), 1)
   496     else
   503     else
   497         ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
   504         ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
   498     lc_setammo:= 0
   505     lc_setammo:= 0
   501 
   508 
   502 procedure ScriptPrintStack;
   509 procedure ScriptPrintStack;
   503 var n, i : LongInt;
   510 var n, i : LongInt;
   504 begin
   511 begin
   505     n:= lua_gettop(luaState);
   512     n:= lua_gettop(luaState);
   506     WriteLnToConsole('LUA: Stack (' + inttostr(n) + ' elements):');
   513     WriteLnToConsole('Lua: Stack (' + inttostr(n) + ' elements):');
   507     for i:= 1 to n do
   514     for i:= 1 to n do
   508         if not lua_isboolean(luaState, i) then
   515         if not lua_isboolean(luaState, i) then
   509             WriteLnToConsole('LUA:  ' + inttostr(i) + ': ' + lua_tostring(luaState, i))
   516             WriteLnToConsole('Lua:  ' + inttostr(i) + ': ' + lua_tostring(luaState, i))
   510         else if lua_toboolean(luaState, i) then
   517         else if lua_toboolean(luaState, i) then
   511             WriteLnToConsole('LUA:  ' + inttostr(i) + ': true')
   518             WriteLnToConsole('Lua:  ' + inttostr(i) + ': true')
   512         else
   519         else
   513             WriteLnToConsole('LUA:  ' + inttostr(i) + ': false');
   520             WriteLnToConsole('Lua:  ' + inttostr(i) + ': false');
   514 end;
   521 end;
   515 
   522 
   516 procedure ScriptClearStack;
   523 procedure ScriptClearStack;
   517 begin
   524 begin
   518 lua_settop(luaState, 0)
   525 lua_settop(luaState, 0)
   604 procedure ScriptLoad(name : shortstring);
   611 procedure ScriptLoad(name : shortstring);
   605 var ret : LongInt;
   612 var ret : LongInt;
   606 begin
   613 begin
   607 ret:= luaL_loadfile(luaState, Str2PChar(name));
   614 ret:= luaL_loadfile(luaState, Str2PChar(name));
   608 if ret <> 0 then
   615 if ret <> 0 then
   609     WriteLnToConsole('LUA: Failed to load ' + name + '(error ' + IntToStr(ret) + ')')
   616     LuaError('Lua: Failed to load ' + name + '(error ' + IntToStr(ret) + ')')
   610 else
   617 else
   611     begin
   618     begin
   612     WriteLnToConsole('LUA: ' + name + ' loaded');
   619     WriteLnToConsole('Lua: ' + name + ' loaded');
   613     // call the script file
   620     // call the script file
   614     lua_pcall(luaState, 0, 0, 0);
   621     lua_pcall(luaState, 0, 0, 0);
   615     ScriptLoaded:= true
   622     ScriptLoaded:= true
   616     end
   623     end
   617 end;
   624 end;
   636     exit;
   643     exit;
   637 SetGlobals;
   644 SetGlobals;
   638 lua_getglobal(luaState, Str2PChar(fname));
   645 lua_getglobal(luaState, Str2PChar(fname));
   639 if lua_pcall(luaState, 0, 0, 0) <> 0 then
   646 if lua_pcall(luaState, 0, 0, 0) <> 0 then
   640     begin
   647     begin
   641     WriteLnToConsole('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
   648     LuaError('Lua: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
   642     lua_pop(luaState, 1)
   649     lua_pop(luaState, 1)
   643     end;
   650     end;
   644 GetGlobals;
   651 GetGlobals;
   645 end;
   652 end;
   646 
   653 
   670 lua_pushinteger(luaState, par3);
   677 lua_pushinteger(luaState, par3);
   671 lua_pushinteger(luaState, par4);
   678 lua_pushinteger(luaState, par4);
   672 ScriptCall:= 0;
   679 ScriptCall:= 0;
   673 if lua_pcall(luaState, 4, 1, 0) <> 0 then
   680 if lua_pcall(luaState, 4, 1, 0) <> 0 then
   674     begin
   681     begin
   675     WriteLnToConsole('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
   682     LuaError('Lua: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
   676     lua_pop(luaState, 1)
   683     lua_pop(luaState, 1)
   677     end
   684     end
   678 else
   685 else
   679     begin
   686     begin
   680     ScriptCall:= lua_tointeger(luaState, -1);
   687     ScriptCall:= lua_tointeger(luaState, -1);