hedgewars/uScript.pas
changeset 10312 eda8d563f677
parent 10306 4fca8bcfaff0
child 10346 dd22bcf08e4f
equal deleted inserted replaced
10311:30b5fab302f6 10312:eda8d563f677
    46 function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt;
    46 function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt;
    47 function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt;
    47 function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt;
    48 function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
    48 function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
    49 function ScriptExists(fname : shortstring) : boolean;
    49 function ScriptExists(fname : shortstring) : boolean;
    50 
    50 
       
    51 procedure LuaParseString(s: shortString);
    51 
    52 
    52 //function ParseCommandOverride(key, value : shortstring) : shortstring;  This did not work out well
    53 //function ParseCommandOverride(key, value : shortstring) : shortstring;  This did not work out well
    53 
    54 
    54 procedure initModule;
    55 procedure initModule;
    55 procedure freeModule;
    56 procedure freeModule;
   104 procedure ScriptApplyAmmoStore; forward;
   105 procedure ScriptApplyAmmoStore; forward;
   105 procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward;
   106 procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward;
   106 procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte); forward;
   107 procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte); forward;
   107 
   108 
   108 var LuaDebugInfo: lua_Debug;
   109 var LuaDebugInfo: lua_Debug;
       
   110 
       
   111 procedure LuaParseString(s: shortString);
       
   112 begin
       
   113     AddFileLog('[Lua] input string: ' + s);
       
   114     AddChatString(#3 + '[Lua] > ' + s);
       
   115     if luaL_dostring(luaState, Str2PChar(s)) <> 0 then
       
   116         begin
       
   117         AddFileLog('[Lua] input string parsing error!');
       
   118         AddChatString(#5 + '[Lua] Error while parsing!');
       
   119         end;
       
   120 end;
   109 
   121 
   110 function LuaUpdateDebugInfo(): Boolean;
   122 function LuaUpdateDebugInfo(): Boolean;
   111 begin
   123 begin
   112     FillChar(LuaDebugInfo, sizeof(LuaDebugInfo), 0);
   124     FillChar(LuaDebugInfo, sizeof(LuaDebugInfo), 0);
   113 
   125 
  2382 ret:= lua_load(luaState, @physfsReader, f, Str2PChar(s));
  2394 ret:= lua_load(luaState, @physfsReader, f, Str2PChar(s));
  2383 pfsClose(f);
  2395 pfsClose(f);
  2384 
  2396 
  2385 if ret <> 0 then
  2397 if ret <> 0 then
  2386     begin
  2398     begin
  2387     LuaError('Lua: Failed to load ' + name + '(error ' + IntToStr(ret) + ')');
  2399     LuaError('Failed to load ' + name + '(error ' + IntToStr(ret) + ')');
  2388     LuaError('Lua: ' + lua_tostring(luaState, -1));
  2400     LuaError(lua_tostring(luaState, -1));
  2389     end
  2401     end
  2390 else
  2402 else
  2391     begin
  2403     begin
  2392     WriteLnToConsole('Lua: ' + name + ' loaded');
  2404     WriteLnToConsole('Lua: ' + name + ' loaded');
  2393     // call the script file
  2405     // call the script file
  2429     exit;
  2441     exit;
  2430 SetGlobals;
  2442 SetGlobals;
  2431 lua_getglobal(luaState, Str2PChar(fname));
  2443 lua_getglobal(luaState, Str2PChar(fname));
  2432 if lua_pcall(luaState, 0, 0, 0) <> 0 then
  2444 if lua_pcall(luaState, 0, 0, 0) <> 0 then
  2433     begin
  2445     begin
  2434     LuaError('Lua: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
  2446     LuaError('Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
  2435     lua_pop(luaState, 1)
  2447     lua_pop(luaState, 1)
  2436     end;
  2448     end;
  2437 GetGlobals;
  2449 GetGlobals;
  2438 end;
  2450 end;
  2439 
  2451 
  2485 lua_pushinteger(luaState, par3);
  2497 lua_pushinteger(luaState, par3);
  2486 lua_pushinteger(luaState, par4);
  2498 lua_pushinteger(luaState, par4);
  2487 ScriptCall:= 0;
  2499 ScriptCall:= 0;
  2488 if lua_pcall(luaState, 4, 1, 0) <> 0 then
  2500 if lua_pcall(luaState, 4, 1, 0) <> 0 then
  2489     begin
  2501     begin
  2490     LuaError('Lua: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
  2502     LuaError('Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
  2491     lua_pop(luaState, 1)
  2503     lua_pop(luaState, 1)
  2492     end
  2504     end
  2493 else
  2505 else
  2494     begin
  2506     begin
  2495     ScriptCall:= lua_tointeger(luaState, -1);
  2507     ScriptCall:= lua_tointeger(luaState, -1);