hedgewars/uScript.pas
changeset 15968 91c487e7d11d
parent 15950 77f1973611ec
child 15975 2146cb7be36f
equal deleted inserted replaced
15967:f362e82cddcf 15968:91c487e7d11d
   306         end
   306         end
   307     else
   307     else
   308         LuaToSoundOrd:= i;
   308         LuaToSoundOrd:= i;
   309 end;
   309 end;
   310 
   310 
       
   311 function LuaToMsgStrIdOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
       
   312 begin
       
   313     if lua_isnoneornil(L, i) then i:= -1
       
   314     else i:= Trunc(lua_tonumber(L, i));
       
   315     if (i < ord(Low(TMsgStrId))) or (i > ord(High(TMsgStrId))) then
       
   316         begin
       
   317         LuaCallError('Invalid message ID!', call, paramsyntax);
       
   318         LuaToMsgStrIdOrd:= -1;
       
   319         end
       
   320     else
       
   321         LuaToMsgStrIdOrd:= i;
       
   322 end;
       
   323 
       
   324 function LuaToGoalStrIdOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
       
   325 begin
       
   326     if lua_isnoneornil(L, i) then i:= -1
       
   327     else i:= Trunc(lua_tonumber(L, i));
       
   328     if (i < ord(Low(TGoalStrId))) or (i > ord(High(TGoalStrId))) then
       
   329         begin
       
   330         LuaCallError('Invalid goal string ID!', call, paramsyntax);
       
   331         LuaToGoalStrIdOrd:= -1;
       
   332         end
       
   333     else
       
   334         LuaToGoalStrIdOrd:= i;
       
   335 end;
       
   336 
   311 function LuaToHogEffectOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   337 function LuaToHogEffectOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   312 begin
   338 begin
   313     if lua_isnoneornil(L, i) then i:= -1
   339     if lua_isnoneornil(L, i) then i:= -1
   314     else i:= Trunc(lua_tonumber(L, i));
   340     else i:= Trunc(lua_tonumber(L, i));
   315     if (i < ord(Low(THogEffect))) or (i > ord(High(THogEffect))) then
   341     if (i < ord(Low(THogEffect))) or (i > ord(High(THogEffect))) then
   580 function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
   606 function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
   581 begin
   607 begin
   582     L:= L; // avoid compiler hint
   608     L:= L; // avoid compiler hint
   583     HideMission;
   609     HideMission;
   584     lc_hidemission:= 0;
   610     lc_hidemission:= 0;
       
   611 end;
       
   612 
       
   613 function lc_getenginestring(L : Plua_state) : LongInt; Cdecl;
       
   614 var stringType: shortstring;
       
   615     msgId: LongInt;
       
   616 const callStr = 'GetEngineString';
       
   617       paramsStr = 'stringType, msgId';
       
   618 begin
       
   619     if CheckLuaParamCount(L, 2, callStr, paramsStr) then
       
   620         begin
       
   621             stringType:= lua_tostring(L, 1);
       
   622             if (not lua_isnumber(L, 2)) then
       
   623                 begin
       
   624                 LuaError('Argument ''msgId'' must be a number!');
       
   625                 lua_pushnil(L);
       
   626                 end
       
   627             else if stringType = 'TMsgStrId' then
       
   628                 begin
       
   629                 msgId:= LuaToMsgStrIdOrd(L, 2, callStr, paramsStr);
       
   630                 if msgId = -1 then
       
   631                     lua_pushnil(L)
       
   632                 else
       
   633                     lua_pushstring(L, PChar(trmsg[TMsgStrId(msgId)]))
       
   634                 end
       
   635             else if stringType = 'TGoalStrId' then
       
   636                 begin
       
   637                 msgId:= LuaToGoalStrIdOrd(L, 2, callStr, paramsStr);
       
   638                 if msgId = -1 then
       
   639                     lua_pushnil(L)
       
   640                 else
       
   641                     lua_pushstring(L, PChar(trgoal[TGoalStrId(msgId)]));
       
   642                 end
       
   643             else
       
   644                 begin
       
   645                 LuaError('Invalid stringType!');
       
   646                 lua_pushnil(L);
       
   647                 end
       
   648         end
       
   649     else
       
   650         lua_pushnil(L);
       
   651     lc_getenginestring:= 1;
   585 end;
   652 end;
   586 
   653 
   587 function lc_setammotexts(L : Plua_State) : LongInt; Cdecl;
   654 function lc_setammotexts(L : Plua_State) : LongInt; Cdecl;
   588 const
   655 const
   589     callStr = 'SetAmmoTexts';
   656     callStr = 'SetAmmoTexts';
  4255     he : THogEffect;
  4322     he : THogEffect;
  4256     cg : TCapGroup;
  4323     cg : TCapGroup;
  4257     spr: TSprite;
  4324     spr: TSprite;
  4258     mg : TMapGen;
  4325     mg : TMapGen;
  4259     we : TWorldEdge;
  4326     we : TWorldEdge;
       
  4327     msi: TMsgStrId;
       
  4328     gsi: TGoalStrId;
  4260 begin
  4329 begin
  4261 // initialize lua
  4330 // initialize lua
  4262 luaState:= lua_open;
  4331 luaState:= lua_open;
  4263 if checkFails(luaState <> nil, 'lua_open failed', true) then exit;
  4332 if checkFails(luaState <> nil, 'lua_open failed', true) then exit;
  4264 
  4333 
  4372 for mg:= Low(TMapGen) to High(TMapGen) do
  4441 for mg:= Low(TMapGen) to High(TMapGen) do
  4373     ScriptSetInteger(EnumToStr(mg), ord(mg));
  4442     ScriptSetInteger(EnumToStr(mg), ord(mg));
  4374 
  4443 
  4375 for we:= Low(TWorldEdge) to High(TWorldEdge) do
  4444 for we:= Low(TWorldEdge) to High(TWorldEdge) do
  4376     ScriptSetInteger(EnumToStr(we), ord(we));
  4445     ScriptSetInteger(EnumToStr(we), ord(we));
       
  4446 
       
  4447 // register message IDs
       
  4448 for msi:= Low(TMsgStrId) to High(TMsgStrId) do
       
  4449     ScriptSetInteger(EnumToStr(msi), ord(msi));
       
  4450 
       
  4451 for gsi:= Low(TGoalStrId) to High(TGoalStrId) do
       
  4452     ScriptSetInteger(EnumToStr(gsi), ord(gsi));
  4377 
  4453 
  4378 ScriptSetLongWord('capcolDefault'   , capcolDefaultLua);
  4454 ScriptSetLongWord('capcolDefault'   , capcolDefaultLua);
  4379 ScriptSetLongWord('capcolSetting'   , capcolSettingLua);
  4455 ScriptSetLongWord('capcolSetting'   , capcolSettingLua);
  4380 
  4456 
  4381 ScriptSetInteger('gstDrowning'      , gstDrowning);
  4457 ScriptSetInteger('gstDrowning'      , gstDrowning);
  4483 lua_register(luaState, _P'SetGearVelocity', @lc_setgearvelocity);
  4559 lua_register(luaState, _P'SetGearVelocity', @lc_setgearvelocity);
  4484 lua_register(luaState, _P'GetGearVelocity', @lc_getgearvelocity);
  4560 lua_register(luaState, _P'GetGearVelocity', @lc_getgearvelocity);
  4485 lua_register(luaState, _P'ParseCommand', @lc_parsecommand);
  4561 lua_register(luaState, _P'ParseCommand', @lc_parsecommand);
  4486 lua_register(luaState, _P'ShowMission', @lc_showmission);
  4562 lua_register(luaState, _P'ShowMission', @lc_showmission);
  4487 lua_register(luaState, _P'HideMission', @lc_hidemission);
  4563 lua_register(luaState, _P'HideMission', @lc_hidemission);
       
  4564 lua_register(luaState, _P'GetEngineString', @lc_getenginestring);
  4488 lua_register(luaState, _P'SetAmmoTexts', @lc_setammotexts);
  4565 lua_register(luaState, _P'SetAmmoTexts', @lc_setammotexts);
  4489 lua_register(luaState, _P'SetAmmoDescriptionAppendix', @lc_setammodescriptionappendix);
  4566 lua_register(luaState, _P'SetAmmoDescriptionAppendix', @lc_setammodescriptionappendix);
  4490 lua_register(luaState, _P'AddCaption', @lc_addcaption);
  4567 lua_register(luaState, _P'AddCaption', @lc_addcaption);
  4491 lua_register(luaState, _P'SetAmmo', @lc_setammo);
  4568 lua_register(luaState, _P'SetAmmo', @lc_setammo);
  4492 lua_register(luaState, _P'GetAmmo', @lc_getammo);
  4569 lua_register(luaState, _P'GetAmmo', @lc_getammo);