hedgewars/uScript.pas
changeset 10284 e9c85a0acdd2
parent 10283 f5573ef8cda9
child 10285 03b615d3c6e1
equal deleted inserted replaced
10283:f5573ef8cda9 10284:e9c85a0acdd2
   112     AddChatString(#5 + s);
   112     AddChatString(#5 + s);
   113     if cTestLua then
   113     if cTestLua then
   114         halt(rtnTestLuaErr);
   114         halt(rtnTestLuaErr);
   115 end;
   115 end;
   116 
   116 
   117 procedure LuaCallError(error ,call, paramsyntax: shortstring);
   117 procedure LuaCallError(error, call, paramsyntax: shortstring);
   118 begin
   118 begin
   119     LuaError(call + ': ' + error + '       function syntax: ' + call + ' ( ' + paramsyntax + ' )');
   119     LuaError(call + ': ' + error + '       function syntax: ' + call + ' ( ' + paramsyntax + ' )');
   120 end;
   120 end;
   121 
   121 
   122 procedure LuaParameterCountError(call, paramsyntax: shortstring; wrongcount: LongInt);
   122 procedure LuaParameterCountError(call, paramsyntax: shortstring; wrongcount: LongInt); inline;
   123 begin
   123 begin
   124     // TODO: i18n?
   124     // TODO: i18n?
   125     LuaCallError('Wrong number of parameters (' + inttostr(wrongcount) + ')!', call, paramsyntax);
   125     LuaCallError('Wrong number of parameters (' + inttostr(wrongcount) + ')!', call, paramsyntax);
       
   126 end;
       
   127 
       
   128 // compare with allowed count
       
   129 function CheckLuaParameterCount(L : Plua_State; count: LongInt; call, paramsyntax: shortstring): boolean; inline;
       
   130 var c: LongInt;
       
   131 begin
       
   132     c:= lua_gettop(L);
       
   133     if c <> count then
       
   134         begin
       
   135         LuaParameterCountError(call, paramsyntax, c);
       
   136         exit(false);
       
   137         end;
       
   138 
       
   139     CheckLuaParameterCount:= true;
       
   140 end;
       
   141 
       
   142 // check if is either count1 or count2
       
   143 function CheckAndFetchLuaParameterCount(L : Plua_State; count1, count2: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline;
       
   144 begin
       
   145     actual:= lua_gettop(L);
       
   146     if (actual <> count1) and (actual <> count2) then
       
   147         begin
       
   148         LuaParameterCountError(call, paramsyntax, actual);
       
   149         exit(false);
       
   150         end;
       
   151 
       
   152     CheckAndFetchLuaParameterCount:= true;
       
   153 end;
       
   154 
       
   155 // check if is same or higher as minCount
       
   156 function CheckAndFetchLuaParameterCount(L : Plua_State; minCount: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline;
       
   157 begin
       
   158     actual:= lua_gettop(L);
       
   159     if (actual < minCount) then
       
   160         begin
       
   161         LuaParameterCountError(call, paramsyntax, actual);
       
   162         exit(false);
       
   163         end;
       
   164 
       
   165     CheckAndFetchLuaParameterCount:= true;
   126 end;
   166 end;
   127 
   167 
   128 function LuaToGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   168 function LuaToGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   129 begin
   169 begin
   130     if lua_isnoneornil(L, i) then i:= -1
   170     if lua_isnoneornil(L, i) then i:= -1
   236 // where L contains the state, returns the number of return values on the stack
   276 // where L contains the state, returns the number of return values on the stack
   237 // call lua_gettop(L) to receive number of parameters passed
   277 // call lua_gettop(L) to receive number of parameters passed
   238 
   278 
   239 function lc_band(L: PLua_State): LongInt; Cdecl;
   279 function lc_band(L: PLua_State): LongInt; Cdecl;
   240 begin
   280 begin
   241     if lua_gettop(L) <> 2 then
   281     if CheckLuaParameterCount(L, 2, 'band', 'value1, value2') then
   242         begin
   282         lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1))
   243         LuaParameterCountError('band', 'value1, value2', lua_gettop(L));
   283     else
   244         lua_pushnil(L);
   284         lua_pushnil(L);
   245         end
       
   246     else
       
   247         lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1));
       
   248     lc_band := 1;
   285     lc_band := 1;
   249 end;
   286 end;
   250 
   287 
   251 function lc_bor(L: PLua_State): LongInt; Cdecl;
   288 function lc_bor(L: PLua_State): LongInt; Cdecl;
   252 begin
   289 begin
   253     if lua_gettop(L) <> 2 then
   290     if CheckLuaParameterCount(L, 2, 'bor', 'value1, value2') then
   254         begin
   291         lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1))
   255         LuaParameterCountError('bor', 'value1, value2', lua_gettop(L));
   292     else
   256         lua_pushnil(L);
   293         lua_pushnil(L);
   257         end
       
   258     else
       
   259         lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1));
       
   260     lc_bor := 1;
   294     lc_bor := 1;
   261 end;
   295 end;
   262 
   296 
   263 function lc_bnot(L: PLua_State): LongInt; Cdecl;
   297 function lc_bnot(L: PLua_State): LongInt; Cdecl;
   264 begin
   298 begin
   265     if lua_gettop(L) <> 1 then
   299     if CheckLuaParameterCount(L, 1, 'bnot', 'value') then
   266         begin
   300         lua_pushinteger(L, (not lua_tointeger(L, 1)))
   267         LuaParameterCountError('bnot', 'value', lua_gettop(L));
   301     else
   268         lua_pushnil(L);
   302         lua_pushnil(L);
   269         end
       
   270     else
       
   271         lua_pushinteger(L, (not lua_tointeger(L, 1)));
       
   272     lc_bnot := 1;
   303     lc_bnot := 1;
   273 end;
   304 end;
   274 
   305 
   275 function lc_div(L: PLua_State): LongInt; Cdecl;
   306 function lc_div(L: PLua_State): LongInt; Cdecl;
   276 begin
   307 begin
   277     if lua_gettop(L) <> 2 then
   308     if CheckLuaParameterCount(L, 2, 'div', 'dividend, divisor') then
   278         begin
   309         lua_pushinteger(L, lua_tointeger(L, 1) div lua_tointeger(L, 2))
   279         LuaParameterCountError('div', 'dividend, divisor', lua_gettop(L));
   310     else
   280         lua_pushnil(L);
   311         lua_pushnil(L);
   281         end
       
   282     else
       
   283         lua_pushinteger(L, lua_tointeger(L, 1) div lua_tointeger(L, 2));
       
   284     lc_div := 1;
   312     lc_div := 1;
   285 end;
   313 end;
   286 
   314 
   287 function lc_getinputmask(L : Plua_State) : LongInt; Cdecl;
   315 function lc_getinputmask(L : Plua_State) : LongInt; Cdecl;
   288 begin
   316 begin
   289     if lua_gettop(L) <> 0 then
   317     if CheckLuaParameterCount(L, 0, 'GetInputMask', '') then
   290         LuaParameterCountError('GetInputMask', '', lua_gettop(L))
       
   291     else
       
   292         lua_pushinteger(L, InputMask);
   318         lua_pushinteger(L, InputMask);
   293     lc_getinputmask:= 1
   319     lc_getinputmask:= 1
   294 end;
   320 end;
   295 
   321 
   296 function lc_setinputmask(L : Plua_State) : LongInt; Cdecl;
   322 function lc_setinputmask(L : Plua_State) : LongInt; Cdecl;
   297 begin
   323 begin
   298     if lua_gettop(L) <> 1 then
   324     if CheckLuaParameterCount(L, 1, 'SetInputMask', 'mask') then
   299         LuaParameterCountError('SetInputMask', 'mask', lua_gettop(L))
       
   300     else
       
   301         InputMask:= lua_tointeger(L, 1);
   325         InputMask:= lua_tointeger(L, 1);
   302     lc_setinputmask:= 0
   326     lc_setinputmask:= 0
   303 end;
   327 end;
   304 
   328 
   305 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl;
   329 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl;
   306 begin
   330 begin
   307     if lua_gettop(L) = 1 then
   331     if CheckLuaParameterCount(L, 1, 'WriteLnToConsole', 'string') then
   308         begin
       
   309         WriteLnToConsole('Lua: ' + lua_tostring(L ,1));
   332         WriteLnToConsole('Lua: ' + lua_tostring(L ,1));
   310         end
       
   311     else
       
   312         LuaParameterCountError('WriteLnToConsole', 'string', lua_gettop(L));
       
   313     lc_writelntoconsole:= 0;
   333     lc_writelntoconsole:= 0;
   314 end;
   334 end;
   315 
   335 
   316 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl;
   336 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl;
   317 var t: PChar;
   337 var t: PChar;
   318     i,c: LongWord;
   338     i,c: LongWord;
   319     s: shortstring;
   339     s: shortstring;
   320 begin
   340 begin
   321     if lua_gettop(L) = 1 then
   341     if CheckLuaParameterCount(L, 1, 'ParseCommand', 'string') then
   322         begin
   342         begin
   323         t:= lua_tolstring(L, 1, Psize_t(@c));
   343         t:= lua_tolstring(L, 1, Psize_t(@c));
   324 
   344 
   325         for i:= 1 to c do s[i]:= t[i-1];
   345         for i:= 1 to c do s[i]:= t[i-1];
   326         s[0]:= char(c);
   346         s[0]:= char(c);
   327 
   347 
   328         ParseCommand(s, true, true);
   348         ParseCommand(s, true, true);
   329 
   349 
   330         end
   350         end;
   331     else
       
   332         LuaParameterCountError('ParseCommand', 'string', lua_gettop(L));
       
   333     lc_parsecommand:= 0;
   351     lc_parsecommand:= 0;
   334 end;
   352 end;
   335 
   353 
   336 function lc_showmission(L : Plua_State) : LongInt; Cdecl;
   354 function lc_showmission(L : Plua_State) : LongInt; Cdecl;
   337 begin
   355 begin
   338     if lua_gettop(L) = 5 then
   356     if CheckLuaParameterCount(L, 5, 'ShowMission', 'caption, subcaption, text, icon, time') then
   339         begin
       
   340         ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
   357         ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
   341         end
       
   342     else
       
   343         LuaParameterCountError('ShowMission', 'caption, subcaption, text, icon, time', lua_gettop(L));
       
   344     lc_showmission:= 0;
   358     lc_showmission:= 0;
   345 end;
   359 end;
   346 
   360 
   347 function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
   361 function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
   348 begin
   362 begin
   350     HideMission;
   364     HideMission;
   351     lc_hidemission:= 0;
   365     lc_hidemission:= 0;
   352 end;
   366 end;
   353 
   367 
   354 function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl;
   368 function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl;
   355 var i : integer;
   369 var i, n : integer;
   356 begin
   370 begin
   357     if lua_gettop(L) = 0 then
   371     // can have 1 or more arguments
   358         begin
   372     if CheckAndFetchLuaParameterCount(L, 1, 'EnableGameFlags', 'gameFlag, ... ', n) then
   359         LuaParameterCountError('EnableGameFlags', '', lua_gettop(L));
   373         begin
   360         lua_pushnil(L);
   374         for i:= 1 to n do
   361         end
   375             GameFlags := GameFlags or LongWord(lua_tointeger(L, i));
   362     else
   376         ScriptSetInteger('GameFlags', GameFlags);
   363         begin
       
   364             for i:= 1 to lua_gettop(L) do
       
   365                 GameFlags := GameFlags or LongWord(lua_tointeger(L, i));
       
   366             ScriptSetInteger('GameFlags', GameFlags);
       
   367         end;
   377         end;
   368     lc_enablegameflags:= 0;
   378     lc_enablegameflags:= 0;
   369 end;
   379 end;
   370 
   380 
   371 function lc_disablegameflags(L : Plua_State) : LongInt; Cdecl;
   381 function lc_disablegameflags(L : Plua_State) : LongInt; Cdecl;
   372 var i : integer;
   382 var i , n: integer;
   373 begin
   383 begin
   374     if lua_gettop(L) = 0 then
   384     // can have 1 or more arguments
   375         begin
   385     if CheckAndFetchLuaParameterCount(L, 1, 'DisableGameFlags', 'gameFlag, ... ', n) then
   376         LuaParameterCountError('DisableGameFlags', '', lua_gettop(L));
   386         begin
   377         lua_pushnil(L);
   387         for i:= 1 to n do
   378         end
       
   379     else
       
   380         begin
       
   381         for i:= 1 to lua_gettop(L) do
       
   382             GameFlags := GameFlags and (not LongWord(lua_tointeger(L, i)));
   388             GameFlags := GameFlags and (not LongWord(lua_tointeger(L, i)));
   383         ScriptSetInteger('GameFlags', GameFlags);
   389         ScriptSetInteger('GameFlags', GameFlags);
   384         end;
   390         end;
   385     lc_disablegameflags:= 0;
   391     lc_disablegameflags:= 0;
   386 end;
   392 end;
   387 
   393 
   388 function lc_cleargameflags(L : Plua_State) : LongInt; Cdecl;
   394 function lc_cleargameflags(L : Plua_State) : LongInt; Cdecl;
   389 begin
   395 begin
   390     if lua_gettop(L) <> 0 then
   396     if CheckLuaParameterCount(L, 0, 'ClearGameFlags', '') then
   391         begin
       
   392         LuaParameterCountError('ClearGameFlags', '', lua_gettop(L));
       
   393         lua_pushnil(L);
       
   394         end
       
   395     else
       
   396         begin
   397         begin
   397         GameFlags:= 0;
   398         GameFlags:= 0;
   398         ScriptSetInteger('GameFlags', GameFlags);
   399         ScriptSetInteger('GameFlags', GameFlags);
   399         end;
   400         end;
   400     lc_cleargameflags:= 0;
   401     lc_cleargameflags:= 0;
   401 end;
   402 end;
   402 
   403 
   403 function lc_getgameflag(L : Plua_State) : LongInt; Cdecl;
   404 function lc_getgameflag(L : Plua_State) : LongInt; Cdecl;
   404 begin
   405 begin
   405     if lua_gettop(L) <> 1 then
   406     if CheckLuaParameterCount(L, 1, 'GetGameFlag', 'gameflag') then
   406         begin
   407         lua_pushboolean(L, (GameFlags and LongWord(lua_tointeger(L, 1)) <> 0))
   407         LuaParameterCountError('GetGameFlag', 'gameflag', lua_gettop(L));
   408     else
   408         lua_pushnil(L);
   409         lua_pushnil(L);
   409         end
       
   410     else
       
   411         begin
       
   412         lua_pushboolean(L, (GameFlags and LongWord(lua_tointeger(L, 1)) <> 0));
       
   413         end;
       
   414     lc_getgameflag:= 1;
   410     lc_getgameflag:= 1;
   415 end;
   411 end;
   416 
   412 
   417 function lc_addcaption(L : Plua_State) : LongInt; Cdecl;
   413 function lc_addcaption(L : Plua_State) : LongInt; Cdecl;
   418 var cg: LongInt;
   414 var cg: LongInt;
   419 const
   415 const
   420     call = 'AddCaption';
   416     call = 'AddCaption';
   421     params = 'text [, color, captiongroup]';
   417     params = 'text [, color, captiongroup]';
   422 begin
   418 begin
   423     if lua_gettop(L) = 1 then
   419     if CheckAndFetchLuaParameterCount(L, 1, 3, call, params, cg) then
   424         AddCaption(lua_tostringA(L, 1), cWhiteColor, capgrpMessage)
   420         begin
   425     else if lua_gettop(L) = 3 then
   421         if cg = 1 then
   426         begin
   422             AddCaption(lua_tostringA(L, 1), cWhiteColor, capgrpMessage)
   427         cg:= LuaToCapGroupOrd(L, 3, call, params);
   423         else
   428         AddCaption(lua_tostringA(L, 1), lua_tointeger(L, 2) shr 8, TCapGroup(cg));
   424             begin
   429         end
   425             cg:= LuaToCapGroupOrd(L, 3, call, params);
   430     else
   426             if cg >= 0 then
   431         LuaParameterCountError(call, params, lua_gettop(L));
   427                 AddCaption(lua_tostringA(L, 1), lua_tointeger(L, 2) shr 8, TCapGroup(cg));
       
   428             end
       
   429         end;
   432     lc_addcaption:= 0;
   430     lc_addcaption:= 0;
   433 end;
   431 end;
   434 
   432 
   435 function lc_campaignlock(L : Plua_State) : LongInt; Cdecl;
   433 function lc_campaignlock(L : Plua_State) : LongInt; Cdecl;
   436 begin
   434 begin
   437     if lua_gettop(L) = 1 then
   435     if CheckLuaParameterCount(L, 1, 'CampaignLock', 'TODO') then
   438         begin
   436         begin
   439         // to be done
   437         // TODO
   440         end
   438         end;
   441     else
       
   442         LuaParameterCountError('CampaignLock', 'TODO', lua_gettop(L));
       
   443     lc_campaignlock:= 0;
   439     lc_campaignlock:= 0;
   444 end;
   440 end;
   445 
   441 
   446 function lc_campaignunlock(L : Plua_State) : LongInt; Cdecl;
   442 function lc_campaignunlock(L : Plua_State) : LongInt; Cdecl;
   447 begin
   443 begin
   448     if lua_gettop(L) = 1 then
   444     if CheckLuaParameterCount(L, 1, 'CampaignUnlock', 'TODO') then
   449         begin
   445         begin
   450         // to be done
   446         // TODO
   451         end
   447         end;
   452     else
       
   453         LuaParameterCountError('CampaignUnlock', 'TODO', lua_gettop(L));
       
   454     lc_campaignunlock:= 0;
   448     lc_campaignunlock:= 0;
   455 end;
   449 end;
   456 
   450 
   457 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
   451 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
   458 var gear: PGear;
   452 var gear: PGear;
   459 begin
   453 begin
   460     if lua_gettop(L) <> 4 then
   454     if CheckLuaParameterCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then
   461         begin
       
   462         LuaParameterCountError('SpawnFakeHealthCrate', 'x, y, explode, poison', lua_gettop(L));
       
   463         lua_pushnil(L);
       
   464         end
       
   465     else
       
   466         begin
   455         begin
   467         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   456         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   468         HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   457         HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   469         lua_pushinteger(L, gear^.uid);
   458         lua_pushinteger(L, gear^.uid);
   470         end;
   459         end
       
   460     else
       
   461         lua_pushnil(L);
   471     lc_spawnfakehealthcrate := 1;
   462     lc_spawnfakehealthcrate := 1;
   472 end;
   463 end;
   473 
   464 
   474 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
   465 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
   475 var gear: PGear;
   466 var gear: PGear;
   476 begin
   467 begin
   477     if lua_gettop(L) <> 4 then
   468     if CheckLuaParameterCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then
   478         begin
       
   479         LuaParameterCountError('SpawnFakeAmmoCrate', 'x, y, explode, poison', lua_gettop(L));
       
   480         lua_pushnil(L);
       
   481         end
       
   482     else
       
   483         begin
   469         begin
   484         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   470         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   485         AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   471         AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   486         lua_pushinteger(L, gear^.uid);
   472         lua_pushinteger(L, gear^.uid);
   487         end;
   473         end
       
   474     else
       
   475         lua_pushnil(L);
   488     lc_spawnfakeammocrate := 1;
   476     lc_spawnfakeammocrate := 1;
   489 end;
   477 end;
   490 
   478 
   491 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
   479 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
   492 var gear: PGear;
   480 var gear: PGear;
   493 begin
   481 begin
   494     if lua_gettop(L) <> 4 then
   482     if CheckLuaParameterCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then
   495         begin
       
   496         LuaParameterCountError('SpawnFakeUtilityCrate', 'x, y, explode, poison', lua_gettop(L));
       
   497         lua_pushnil(L);
       
   498         end
       
   499     else
       
   500         begin
   483         begin
   501         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   484         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   502         UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   485         UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   503         lua_pushinteger(L, gear^.uid);
   486         lua_pushinteger(L, gear^.uid);
   504         end;
   487         end
       
   488     else
       
   489         lua_pushnil(L);
   505     lc_spawnfakeutilitycrate := 1;
   490     lc_spawnfakeutilitycrate := 1;
   506 end;
   491 end;
   507 
   492 
   508 function lc_spawnhealthcrate(L: Plua_State) : LongInt; Cdecl;
   493 function lc_spawnhealthcrate(L: Plua_State) : LongInt; Cdecl;
   509 var gear: PGear;
   494 var gear: PGear;
   510 var health: LongInt;
   495 var health, n: LongInt;
   511 begin
   496 begin
   512     if (lua_gettop(L) < 2) or (lua_gettop(L) > 3) then
   497     if CheckAndFetchLuaParameterCount(L, 2, 3, 'SpawnHealthCrate', 'x, y [, health]', n) then
   513         begin
   498         begin
   514         LuaParameterCountError('SpawnHealthCrate', 'x, y [, health]', lua_gettop(L));
   499         if n = 3 then
   515         lua_pushnil(L);
       
   516         end
       
   517     else
       
   518         begin
       
   519         if lua_gettop(L) = 3 then
       
   520             health:= lua_tointeger(L, 3)
   500             health:= lua_tointeger(L, 3)
   521         else
   501         else
   522             health:= cHealthCaseAmount;
   502             health:= cHealthCaseAmount;
   523         gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health, 0);
   503         gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health, 0);
   524         if gear <> nil then
   504         if gear <> nil then
   525             lua_pushinteger(L, gear^.uid)
   505             lua_pushinteger(L, gear^.uid)
   526         else
   506         else
   527             lua_pushnil(L);
   507             lua_pushnil(L);
   528         end;
   508         end
       
   509     else
       
   510         lua_pushnil(L);
   529     lc_spawnhealthcrate := 1;
   511     lc_spawnhealthcrate := 1;
   530 end;
   512 end;
   531 
   513 
   532 function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl;
   514 function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl;
   533 var gear: PGear;
   515 var gear: PGear;
   534 begin
   516     n   : LongInt;
   535     if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then
   517 begin
   536         begin
   518     if CheckAndFetchLuaParameterCount(L, 3, 4, 'SpawnAmmoCrate', 'x, y, content [, amount]', n) then
   537         LuaParameterCountError('SpawnAmmoCrate', 'x, y, content [, amount]', lua_gettop(L));
   519         begin
   538         lua_pushnil(L);
   520         if n = 3 then
   539         end
       
   540     else
       
   541         begin
       
   542         if (lua_gettop(L) = 3) then
       
   543              gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0)
   521              gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0)
   544         else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4));
   522         else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4));
   545         if gear <> nil then
   523         if gear <> nil then
   546             lua_pushinteger(L, gear^.uid)
   524             lua_pushinteger(L, gear^.uid)
   547         else
   525         else
   548             lua_pushnil(L);
   526             lua_pushnil(L);
   549         end;
   527         end
       
   528     else
       
   529         lua_pushnil(L);
   550     lc_spawnammocrate := 1;
   530     lc_spawnammocrate := 1;
   551 end;
   531 end;
   552 
   532 
   553 function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl;
   533 function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl;
   554 var gear: PGear;
   534 var gear: PGear;
   555 begin
   535     n   : LongInt;
   556     if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then
   536 begin
   557         begin
   537     if CheckAndFetchLuaParameterCount(L, 3, 4, 'SpawnUtilityCrate', 'x, y, content [, amount]', n) then
   558         LuaParameterCountError('SpawnUtilityCrate', 'x, y, content [, amount]', lua_gettop(L));
   538         begin
   559         lua_pushnil(L);
   539         if n = 3 then
   560         end
       
   561     else
       
   562         begin
       
   563         if (lua_gettop(L) = 3) then
       
   564              gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0)
   540              gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0)
   565         else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4));
   541         else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4));
   566         if gear <> nil then
   542         if gear <> nil then
   567             lua_pushinteger(L, gear^.uid)
   543             lua_pushinteger(L, gear^.uid)
   568         else
   544         else
   569             lua_pushnil(L);
   545             lua_pushnil(L);
   570        end;
   546        end
       
   547     else
       
   548         lua_pushnil(L);
   571     lc_spawnutilitycrate := 1;
   549     lc_spawnutilitycrate := 1;
   572 end;
   550 end;
   573 
   551 
   574 function lc_addgear(L : Plua_State) : LongInt; Cdecl;
   552 function lc_addgear(L : Plua_State) : LongInt; Cdecl;
   575 var gear : PGear;
   553 var gear : PGear;
   578     gt: TGearType;
   556     gt: TGearType;
   579 const
   557 const
   580     call = 'AddGear';
   558     call = 'AddGear';
   581     params = 'x, y, gearType, state, dx, dy, timer';
   559     params = 'x, y, gearType, state, dx, dy, timer';
   582 begin
   560 begin
   583     if lua_gettop(L) <> 7 then
   561     if CheckLuaParameterCount(L, 7, call, params) then
   584         begin
       
   585         LuaParameterCountError(call, params, lua_gettop(L));
       
   586         lua_pushnil(L); // return value on stack (nil)
       
   587         end
       
   588     else
       
   589         begin
   562         begin
   590         t:= LuaToGearTypeOrd(L, 3, call, params);
   563         t:= LuaToGearTypeOrd(L, 3, call, params);
   591         if t >= 0 then
   564         if t >= 0 then
   592             begin
   565             begin
   593             gt:= TGearType(t);
   566             gt:= TGearType(t);
   602             lastGearByUID:= gear;
   575             lastGearByUID:= gear;
   603             lua_pushinteger(L, gear^.uid)
   576             lua_pushinteger(L, gear^.uid)
   604             end
   577             end
   605         else
   578         else
   606             lua_pushnil(L);
   579             lua_pushnil(L);
   607         end;
   580         end
       
   581     else
       
   582         lua_pushnil(L);
   608     lc_addgear:= 1; // 1 return value
   583     lc_addgear:= 1; // 1 return value
   609 end;
   584 end;
   610 
   585 
   611 function lc_deletegear(L : Plua_State) : LongInt; Cdecl;
   586 function lc_deletegear(L : Plua_State) : LongInt; Cdecl;
   612 var gear : PGear;
   587 var gear : PGear;
   613 begin
   588 begin
   614     if lua_gettop(L) <> 1 then
   589     if CheckLuaParameterCount(L, 1, 'DeleteGear', 'gearUid') then
   615         begin
       
   616         LuaParameterCountError('DeleteGear', 'gearUid', lua_gettop(L));
       
   617         end
       
   618     else
       
   619         begin
   590         begin
   620         gear:= GearByUID(lua_tointeger(L, 1));
   591         gear:= GearByUID(lua_tointeger(L, 1));
   621         if gear <> nil then
   592         if gear <> nil then
   622             gear^.Message:= gear^.Message or gmDelete;
   593             gear^.Message:= gear^.Message or gmDelete;
   623         end;
   594         end;
   633 const
   604 const
   634     call = 'AddVisualGear';
   605     call = 'AddVisualGear';
   635     params = 'x, y, visualGearType, state, critical';
   606     params = 'x, y, visualGearType, state, critical';
   636 begin
   607 begin
   637     uid:= 0;
   608     uid:= 0;
   638     if lua_gettop(L) <> 5 then
   609     if CheckLuaParameterCount(L, 5, call, params) then
   639         begin
       
   640         LuaParameterCountError(call, params, lua_gettop(L));
       
   641         lua_pushnil(L); // return value on stack (nil)
       
   642         end
       
   643     else
       
   644         begin
   610         begin
   645         s:= LuaToVisualGearTypeOrd(L, 3, call, params);
   611         s:= LuaToVisualGearTypeOrd(L, 3, call, params);
   646         if s >= 0 then
   612         if s >= 0 then
   647             begin
   613             begin
   648             vgt:= TVisualGearType(s);
   614             vgt:= TVisualGearType(s);
   654             vg:= AddVisualGear(x, y, vgt, s, c);
   620             vg:= AddVisualGear(x, y, vgt, s, c);
   655             if vg <> nil then
   621             if vg <> nil then
   656                 begin
   622                 begin
   657                 lastVisualGearByUID:= vg;
   623                 lastVisualGearByUID:= vg;
   658                 uid:= vg^.uid;
   624                 uid:= vg^.uid;
       
   625                 lua_pushinteger(L, uid);
   659                 end;
   626                 end;
   660             end;
   627             end
   661         end;
   628             else
   662     lua_pushinteger(L, uid);
   629                 lua_pushnil(L);
       
   630         end
       
   631     else
       
   632         lua_pushnil(L); // return value on stack (nil)
   663     lc_addvisualgear:= 1; // 1 return value
   633     lc_addvisualgear:= 1; // 1 return value
   664 end;
   634 end;
   665 
   635 
   666 function lc_deletevisualgear(L : Plua_State) : LongInt; Cdecl;
   636 function lc_deletevisualgear(L : Plua_State) : LongInt; Cdecl;
   667 var vg : PVisualGear;
   637 var vg : PVisualGear;
  2043 end;
  2013 end;
  2044 
  2014 
  2045 function lc_placesprite(L : Plua_State) : LongInt; Cdecl;
  2015 function lc_placesprite(L : Plua_State) : LongInt; Cdecl;
  2046 var spr   : TSprite;
  2016 var spr   : TSprite;
  2047     lf    : Word;
  2017     lf    : Word;
  2048     n : LongInt;
  2018     i, n : LongInt;
  2049     placed: boolean;
  2019     placed: boolean;
  2050 const
  2020 const
  2051     call = 'PlaceSprite';
  2021     call = 'PlaceSprite';
  2052     params = 'x, y, sprite, frameIdx [, landFlags]';
  2022     params = 'x, y, sprite, frameIdx [, landFlags, ... ]';
  2053 begin
  2023 begin
  2054     placed:= false;
  2024     placed:= false;
  2055     n:= lua_gettop(L);
  2025     if CheckAndFetchLuaParameterCount(L, 4, call, params, n) then
  2056     if (n < 4) or (n > 5) then
  2026         begin
  2057         LuaParameterCountError(call, params, lua_gettop(L))
  2027         lf:= 0;
  2058     else
  2028 
  2059         begin
  2029         // accept any amount of landflags, loop is never executed if n>5
  2060         // get landflags, if specified
  2030         for i:= 5 to n do
  2061         if n = 5 then
  2031             lf:= lf or lua_tointeger(L, i);
  2062             lf:= lua_tointeger(L, 5)
       
  2063         else
       
  2064             lf:= 0;
       
  2065 
  2032 
  2066         n:= LuaToSpriteOrd(L, 3, call, params);
  2033         n:= LuaToSpriteOrd(L, 3, call, params);
  2067         if n >= 0 then
  2034         if n >= 0 then
  2068             begin
  2035             begin
  2069             spr:= TSprite(n);
  2036             spr:= TSprite(n);
  2083 
  2050 
  2084 function lc_placegirder(L : Plua_State) : LongInt; Cdecl;
  2051 function lc_placegirder(L : Plua_State) : LongInt; Cdecl;
  2085 var placed: boolean;
  2052 var placed: boolean;
  2086 begin
  2053 begin
  2087     placed:= false;
  2054     placed:= false;
  2088     if lua_gettop(L) <> 3 then
  2055     if CheckLuaParameterCount(L, 3, 'PlaceGirder', 'x, y, frameIdx') then
  2089         LuaParameterCountError('PlaceGirder', 'x, y, frameIdx', lua_gettop(L))
       
  2090     else
       
  2091         placed:= TryPlaceOnLand(
  2056         placed:= TryPlaceOnLand(
  2092             lua_tointeger(L, 1) - SpritesData[sprAmGirder].Width div 2,
  2057             lua_tointeger(L, 1) - SpritesData[sprAmGirder].Width div 2,
  2093             lua_tointeger(L, 2) - SpritesData[sprAmGirder].Height div 2,
  2058             lua_tointeger(L, 2) - SpritesData[sprAmGirder].Height div 2,
  2094             sprAmGirder, lua_tointeger(L, 3), true, false);
  2059             sprAmGirder, lua_tointeger(L, 3), true, false);
  2095 
  2060 
  2097     lc_placegirder:= 1
  2062     lc_placegirder:= 1
  2098 end;
  2063 end;
  2099 
  2064 
  2100 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl;
  2065 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl;
  2101 begin
  2066 begin
  2102     if lua_gettop(L) <> 0 then
  2067     if CheckLuaParameterCount(L, 0, 'GetCurAmmoType', '') then
  2103         LuaParameterCountError('GetCurAmmoType', '', lua_gettop(L))
       
  2104     else
       
  2105         lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType));
  2068         lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType));
  2106     lc_getcurammotype := 1;
  2069     lc_getcurammotype := 1;
  2107 end;
  2070 end;
  2108 
  2071 
  2109 function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl;
  2072 function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl;
  2110 begin
  2073 begin
  2111     if lua_gettop(L) <> 2 then
  2074     if CheckLuaParameterCount(L, 2, 'SaveCampaignVar', 'varname, value') then
  2112         LuaParameterCountError('SaveCampaignVar', 'varname, value', lua_gettop(L))
       
  2113     else begin
       
  2114         SendIPC('V!' + lua_tostring(L, 1) + ' ' + lua_tostring(L, 2) + #0);
  2075         SendIPC('V!' + lua_tostring(L, 1) + ' ' + lua_tostring(L, 2) + #0);
  2115     end;
       
  2116     lc_savecampaignvar := 0;
  2076     lc_savecampaignvar := 0;
  2117 end;
  2077 end;
  2118 
  2078 
  2119 function lc_getcampaignvar(L : Plua_State): LongInt; Cdecl;
  2079 function lc_getcampaignvar(L : Plua_State): LongInt; Cdecl;
  2120 begin
  2080 begin
  2121     if (lua_gettop(L) <> 1) then
  2081     if CheckLuaParameterCount(L, 1, 'GetCampaignVar', 'varname') then
  2122         LuaParameterCountError('GetCampaignVar', 'varname', lua_gettop(L))
       
  2123     else
       
  2124         SendIPCAndWaitReply('V?' + lua_tostring(L, 1) + #0);
  2082         SendIPCAndWaitReply('V?' + lua_tostring(L, 1) + #0);
  2125     lua_pushstring(L, str2pchar(CampaignVariable));
  2083     lua_pushstring(L, str2pchar(CampaignVariable));
  2126     lc_getcampaignvar := 1;
  2084     lc_getcampaignvar := 1;
  2127 end;
  2085 end;
  2128 
  2086 
  2129 function lc_hidehog(L: Plua_State): LongInt; Cdecl;
  2087 function lc_hidehog(L: Plua_State): LongInt; Cdecl;
  2130 var gear: PGear;
  2088 var gear: PGear;
  2131 begin
  2089 begin
  2132     if lua_gettop(L) <> 1 then
  2090     if CheckLuaParameterCount(L, 1, 'HideHog', 'gearUid') then
  2133         LuaParameterCountError('HideHog', 'gearUid', lua_gettop(L))
       
  2134     else
       
  2135         begin
  2091         begin
  2136         gear:= GearByUID(lua_tointeger(L, 1));
  2092         gear:= GearByUID(lua_tointeger(L, 1));
  2137         HideHog(gear^.hedgehog)
  2093         HideHog(gear^.hedgehog)
  2138         end;
  2094         end;
  2139     lc_hidehog := 0;
  2095     lc_hidehog := 0;
  2141 
  2097 
  2142 function lc_restorehog(L: Plua_State): LongInt; Cdecl;
  2098 function lc_restorehog(L: Plua_State): LongInt; Cdecl;
  2143 var i, h: LongInt;
  2099 var i, h: LongInt;
  2144     uid: LongWord;
  2100     uid: LongWord;
  2145 begin
  2101 begin
  2146     if lua_gettop(L) <> 1 then
  2102     if CheckLuaParameterCount(L, 1, 'RestoreHog', 'gearUid') then
  2147         LuaParameterCountError('RestoreHog', 'gearUid', lua_gettop(L))
       
  2148     else
       
  2149         begin
  2103         begin
  2150         uid:= LongWord(lua_tointeger(L, 1));
  2104         uid:= LongWord(lua_tointeger(L, 1));
  2151         if TeamsCount > 0 then
  2105         if TeamsCount > 0 then
  2152             for i:= 0 to Pred(TeamsCount) do
  2106             for i:= 0 to Pred(TeamsCount) do
  2153                 for h:= 0 to cMaxHHIndex do
  2107                 for h:= 0 to cMaxHHIndex do
  2162 
  2116 
  2163 // boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
  2117 // boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
  2164 function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl;
  2118 function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl;
  2165 var rtn: Boolean;
  2119 var rtn: Boolean;
  2166 begin
  2120 begin
  2167     if lua_gettop(L) <> 5 then
  2121     if CheckLuaParameterCount(L, 5, 'TestRectForObstacle', 'x1, y1, x2, y2, landOnly') then
  2168         begin
       
  2169         LuaParameterCountError('TestRectForObstacle', 'x1, y1, x2, y2, landOnly', lua_gettop(L));
       
  2170         lua_pushnil(L); // return value on stack (nil)
       
  2171         end
       
  2172     else
       
  2173         begin
  2122         begin
  2174         rtn:= TestRectancleForObstacle(
  2123         rtn:= TestRectancleForObstacle(
  2175                     lua_tointeger(L, 1),
  2124                     lua_tointeger(L, 1),
  2176                     lua_tointeger(L, 2),
  2125                     lua_tointeger(L, 2),
  2177                     lua_tointeger(L, 3),
  2126                     lua_tointeger(L, 3),
  2178                     lua_tointeger(L, 4),
  2127                     lua_tointeger(L, 4),
  2179                     lua_toboolean(L, 5)
  2128                     lua_toboolean(L, 5)
  2180                     );
  2129                     );
  2181         lua_pushboolean(L, rtn);
  2130         lua_pushboolean(L, rtn);
  2182         end;
  2131         end
       
  2132     else
       
  2133         lua_pushnil(L); // return value on stack (nil)
  2183     lc_testrectforobstacle:= 1
  2134     lc_testrectforobstacle:= 1
  2184 end;
  2135 end;
  2185 
  2136 
  2186 
  2137 
  2187 function lc_getgravity(L : Plua_State) : LongInt; Cdecl;
  2138 function lc_getgravity(L : Plua_State) : LongInt; Cdecl;
  2188 begin
  2139 begin
  2189     if lua_gettop(L) <> 0 then
  2140     if CheckLuaParameterCount(L, 0, 'GetGravity', '') then
  2190         LuaParameterCountError('GetGravity', '', lua_gettop(L))
  2141         lua_pushinteger(L, hwRound(SignAs(_0_5, cGravity) + (cGravity * 50 / cMaxWindSpeed)));
  2191     else if cGravity.isNegative then
       
  2192         lua_pushinteger(L, hwRound(-_0_5 + (cGravity * 50 / cMaxWindSpeed)))
       
  2193     else
       
  2194         lua_pushinteger(L, hwRound( _0_5 + (cGravity * 50 / cMaxWindSpeed)));
       
  2195     lc_getgravity:= 1
  2142     lc_getgravity:= 1
  2196 end;
  2143 end;
  2197 
  2144 
  2198 function lc_setgravity(L : Plua_State) : LongInt; Cdecl;
  2145 function lc_setgravity(L : Plua_State) : LongInt; Cdecl;
  2199 begin
  2146 begin
  2200     if lua_gettop(L) <> 1 then
  2147     if CheckLuaParameterCount(L, 1, 'SetGravity', 'percent') then
  2201         LuaParameterCountError('SetGravity', 'percent', lua_gettop(L))
       
  2202     else
       
  2203         begin
  2148         begin
  2204         cGravity:= _0_02 * lua_tointeger(L, 1) * cMaxWindSpeed;
  2149         cGravity:= _0_02 * lua_tointeger(L, 1) * cMaxWindSpeed;
  2205         cGravityf:= 0.00025 * lua_tointeger(L, 1) * 0.02
  2150         cGravityf:= 0.00025 * lua_tointeger(L, 1) * 0.02
  2206         end;
  2151         end;
  2207     lc_setgravity:= 0
  2152     lc_setgravity:= 0
  2208 end;
  2153 end;
  2209 
  2154 
  2210 function lc_setwaterline(L : Plua_State) : LongInt; Cdecl;
  2155 function lc_setwaterline(L : Plua_State) : LongInt; Cdecl;
  2211 var iterator: PGear;
  2156 var iterator: PGear;
  2212 begin
  2157 begin
  2213     if lua_gettop(L) <> 1 then
  2158     if CheckLuaParameterCount(L, 1, 'SetWaterLine', 'waterline') then
  2214          LuaParameterCountError('SetWaterLine', 'waterline', lua_gettop(L))
       
  2215     else
       
  2216         begin
  2159         begin
  2217         cWaterLine:= lua_tointeger(L,1);
  2160         cWaterLine:= lua_tointeger(L,1);
  2218         AllInactive:= false;
  2161         AllInactive:= false;
  2219         iterator:= GearsList;
  2162         iterator:= GearsList;
  2220         while iterator <> nil do
  2163         while iterator <> nil do
  2233 end;
  2176 end;
  2234 
  2177 
  2235 function lc_setaihintsongear(L : Plua_State) : LongInt; Cdecl;
  2178 function lc_setaihintsongear(L : Plua_State) : LongInt; Cdecl;
  2236 var gear: PGear;
  2179 var gear: PGear;
  2237 begin
  2180 begin
  2238     if lua_gettop(L) <> 2 then
  2181     if CheckLuaParameterCount(L, 2, 'SetAIHintOnGear', 'gearUid, aiHints') then
  2239         LuaParameterCountError('SetAIHintOnGear', 'gearUid, aiHints', lua_gettop(L))
       
  2240     else
       
  2241         begin
  2182         begin
  2242         gear:= GearByUID(lua_tointeger(L, 1));
  2183         gear:= GearByUID(lua_tointeger(L, 1));
  2243         if gear <> nil then
  2184         if gear <> nil then
  2244             gear^.aihints:= lua_tointeger(L, 2);
  2185             gear^.aihints:= lua_tointeger(L, 2);
  2245         end;
  2186         end;
  2247 end;
  2188 end;
  2248 
  2189 
  2249 
  2190 
  2250 function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl;
  2191 function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl;
  2251 begin
  2192 begin
  2252     if lua_gettop(L) <> 1 then
  2193     if CheckLuaParameterCount(L, 1, 'HedgewarsScriptLoad', 'scriptPath') then
  2253         begin
  2194         ScriptLoad(lua_tostring(L, 1))
  2254         LuaParameterCountError('HedgewarsScriptLoad', 'scriptPath', lua_gettop(L));
  2195     else
  2255         lua_pushnil(L)
  2196         lua_pushnil(L);
  2256         end
       
  2257     else
       
  2258         ScriptLoad(lua_tostring(L, 1));
       
  2259     lc_hedgewarsscriptload:= 0;
  2197     lc_hedgewarsscriptload:= 0;
  2260 end;
  2198 end;
  2261 
  2199 
  2262 
  2200 
  2263 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl;
  2201 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl;
  2264 begin
  2202 begin
  2265     if lua_gettop(L) <> 4 then
  2203     if CheckLuaParameterCount(L, 4, 'DeclareAchievement', 'achievementId, teamname, location, value') then
  2266         LuaParameterCountError('DeclareAchievement', 'achievementId, teamname, location, value', lua_gettop(L))
       
  2267     else
       
  2268         declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4));
  2204         declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4));
  2269     lc_declareachievement:= 0
  2205     lc_declareachievement:= 0
  2270 end;
  2206 end;
  2271 
  2207 
  2272 // stuff for testing the lua API
  2208 // stuff for testing the lua API
  2273 function lc_endluatest(L : Plua_State) : LongInt; Cdecl;
  2209 function lc_endluatest(L : Plua_State) : LongInt; Cdecl;
  2274 begin
  2210 begin
  2275     if lua_gettop(L) <> 1 then
  2211     if CheckLuaParameterCount(L, 1, 'EndLuaAPITest', 'LUA_API_TEST_SUCCESSFUL or LUA_API_TEST_FAILED') then
  2276         begin
       
  2277         LuaParameterCountError('EndLuaAPITest', 'LUA_API_TEST_SUCCESSFUL or LUA_API_TEST_FAILED', lua_gettop(L));
       
  2278         lua_pushnil(L);
       
  2279         lc_endluatest:= 0;
       
  2280         end
       
  2281     else
       
  2282         begin
  2212         begin
  2283         WriteLnToConsole('Lua test finished');
  2213         WriteLnToConsole('Lua test finished');
  2284         halt(lua_tointeger(L, 1));
  2214         halt(lua_tointeger(L, 1));
  2285         end;
  2215         end
       
  2216     else
       
  2217         lua_pushnil(L);
       
  2218     lc_endluatest:= 0;
  2286 end;
  2219 end;
  2287 ///////////////////
  2220 ///////////////////
  2288 
  2221 
  2289 procedure ScriptPrintStack;
  2222 procedure ScriptPrintStack;
  2290 var n, i : LongInt;
  2223 var n, i : LongInt;