hedgewars/uScript.pas
changeset 4647 20b982afbe6e
parent 4629 b5d726bc4f8d
child 4682 0fc1ff341482
equal deleted inserted replaced
4588:5ef5415c4ee1 4647:20b982afbe6e
   825 end;
   825 end;
   826 
   826 
   827 function lc_findplace(L : Plua_State) : LongInt; Cdecl;
   827 function lc_findplace(L : Plua_State) : LongInt; Cdecl;
   828 var gear: PGear;
   828 var gear: PGear;
   829     fall: boolean;
   829     fall: boolean;
       
   830     tryhard: boolean;
   830     left, right: LongInt;
   831     left, right: LongInt;
   831 begin
   832 begin
   832     if lua_gettop(L) <> 4 then
   833     tryhard:= false;
       
   834     if (lua_gettop(L) <> 4) and (lua_gettop(L) <> 5) then
   833         LuaError('Lua: Wrong number of parameters passed to FindPlace!')
   835         LuaError('Lua: Wrong number of parameters passed to FindPlace!')
   834     else
   836     else
   835         begin
   837         begin
   836         gear:= GearByUID(lua_tointeger(L, 1));
   838         gear:= GearByUID(lua_tointeger(L, 1));
   837         fall:= lua_toboolean(L, 2);
   839         fall:= lua_toboolean(L, 2);
   838         left:= lua_tointeger(L, 3);
   840         left:= lua_tointeger(L, 3);
   839         right:= lua_tointeger(L, 4);
   841         right:= lua_tointeger(L, 4);
   840         if gear <> nil then
   842         if lua_gettop(L) = 5 then tryhard:= lua_toboolean(L, 5);
   841             FindPlace(gear, fall, left, right)
   843         if gear <> nil then
   842         end;
   844             FindPlace(gear, fall, left, right, tryhard);
   843     lc_findplace:= 0
   845         if gear <> nil then lua_pushinteger(L, gear^.uid)
       
   846         else lua_pushnil(L);
       
   847         end;
       
   848     lc_findplace:= 1
   844 end;
   849 end;
   845 
   850 
   846 function lc_playsound(L : Plua_State) : LongInt; Cdecl;
   851 function lc_playsound(L : Plua_State) : LongInt; Cdecl;
   847 var gear: PGear;
   852 var gear: PGear;
   848 begin
   853 begin
  1079         lua_pushnil(L);
  1084         lua_pushnil(L);
  1080         end
  1085         end
  1081     else
  1086     else
  1082         lua_pushstring(L, str2pchar(Pathz[ptData]));
  1087         lua_pushstring(L, str2pchar(Pathz[ptData]));
  1083     lc_getdatapath:= 1
  1088     lc_getdatapath:= 1
       
  1089 end;
       
  1090 
       
  1091 function lc_maphasborder(L : Plua_State) : LongInt; Cdecl;
       
  1092 begin
       
  1093     if lua_gettop(L) <> 0 then
       
  1094         begin
       
  1095         LuaError('Lua: Wrong number of parameters passed to MapHasBorder!');
       
  1096         lua_pushnil(L);
       
  1097         end
       
  1098     else
       
  1099         lua_pushboolean(L, hasBorder);
       
  1100     lc_maphasborder:= 1
  1084 end;
  1101 end;
  1085 ///////////////////
  1102 ///////////////////
  1086 
  1103 
  1087 procedure ScriptPrintStack;
  1104 procedure ScriptPrintStack;
  1088 var n, i : LongInt;
  1105 var n, i : LongInt;
  1490 lua_register(luaState, 'GetGearMessage', @lc_getgearmessage);
  1507 lua_register(luaState, 'GetGearMessage', @lc_getgearmessage);
  1491 lua_register(luaState, 'SetGearMessage', @lc_setgearmessage);
  1508 lua_register(luaState, 'SetGearMessage', @lc_setgearmessage);
  1492 lua_register(luaState, 'GetRandom', @lc_getrandom);
  1509 lua_register(luaState, 'GetRandom', @lc_getrandom);
  1493 lua_register(luaState, 'SetWind', @lc_setwind);
  1510 lua_register(luaState, 'SetWind', @lc_setwind);
  1494 lua_register(luaState, 'GetDataPath', @lc_getdatapath);
  1511 lua_register(luaState, 'GetDataPath', @lc_getdatapath);
       
  1512 lua_register(luaState, 'MapHasBorder', @lc_maphasborder);
  1495 
  1513 
  1496 
  1514 
  1497 ScriptClearStack; // just to be sure stack is empty
  1515 ScriptClearStack; // just to be sure stack is empty
  1498 ScriptLoaded:= false;
  1516 ScriptLoaded:= false;
  1499 end;
  1517 end;