diff --git a/src/game/g_scripts.pas b/src/game/g_scripts.pas
index 43fe3afc42227e6d453417bc604a2b7e2265de7f..31a8a0060623abb48fc99720a0af4147a27898c9 100644 (file)
--- a/src/game/g_scripts.pas
+++ b/src/game/g_scripts.pas
function g_Scripts_Init(): Boolean;
procedure g_Scripts_Reset(What: Integer);
-function g_Scripts_ProcExec(PName: string; const Args: array of const): Integer;
+function g_Scripts_ProcExec(PName: string; const Args: array of const; Namespace: string = ''): Integer;
function g_Scripts_ProcExists(PName: string): Boolean;
function g_Scripts_ProcInstall(PName: string; PPtr: PScriptProc): Boolean;
function g_Scripts_Load(Text: string): Boolean;
if not g_Scripts_ProcInstall('conprint', SP_Lua_ConPrint) then Exit;
+ if not g_Scripts_ProcInstall('spawn_item', SP_Lua_SpawnItem) then Exit;
+ if not g_Scripts_ProcInstall('spawn_shot', SP_Lua_SpawnShot) then Exit;
+ if not g_Scripts_ProcInstall('spawn_effect', SP_Lua_SpawnEffect) then Exit;
+ if not g_Scripts_ProcInstall('spawn_monster', SP_Lua_SpawnMonster) then Exit;
+
Result := True;
end;
Result := True;
end;
-function g_Scripts_ProcExec(PName: string; const Args: array of const): Integer;
+function g_Scripts_ProcExec(PName: string; const Args: array of const; Namespace: string = ''): Integer;
var
i: Integer;
begin
Result := -255;
if not gScriptInit then Exit;
- lua_getglobal(gScriptCtx, 'game');
- lua_pushstring(gScriptCtx, PName);
- lua_gettable(gScriptCtx, -2);
+ if Namespace = '' then
+ lua_getglobal(gScriptCtx, PChar(PName))
+ else
+ begin
+ lua_getglobal(gScriptCtx, PChar(Namespace));
+ lua_pushstring(gScriptCtx, PName);
+ lua_gettable(gScriptCtx, -2);
+ end;
+
if not lua_isfunction(gScriptCtx, -1) then
begin
- g_Console_Add('SCRIPT: ProcExec(' + PName + ') error: no such function');
+ g_Console_Add('SCRIPT: ProcExec(' + Namespace + '.' + PName + ') error: no such function');
Exit;
end;
if lua_pcall(gScriptCtx, Length(Args), 1, 0) <> 0 then
begin
- g_Console_Add('SCRIPT: ProcExec(' + PName + ') error: ' + lua_tostring(gScriptCtx, -1));
+ g_Console_Add('SCRIPT: ProcExec(' + Namespace + '.' + PName + ') error: ' + lua_tostring(gScriptCtx, -1));
Exit;
end;
- if not lua_isnumber(gScriptCtx, -1) then
+ Result := 0;
+ if lua_isnumber(gScriptCtx, -1) then
begin
- g_Console_Add('SCRIPT: ProcExec(' + PName + ') error: return value is not a number');
- Exit;
+ Result := lua_tointeger(gScriptCtx, -1);
+ lua_pop(gScriptCtx, 1);
end;
-
- Result := lua_tointeger(gScriptCtx, -1);
- lua_pop(gScriptCtx, 1);
end;
function g_Scripts_Load(Text: string): Boolean;