X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_scripts.pas;h=31a8a0060623abb48fc99720a0af4147a27898c9;hb=c0e0a28f9c2ac9eb8e62791655d9baa3b6f978a0;hp=43fe3afc42227e6d453417bc604a2b7e2265de7f;hpb=0aed9f9d49f034aad7d8856db00fe42f3303826d;p=d2df-sdl.git diff --git a/src/game/g_scripts.pas b/src/game/g_scripts.pas index 43fe3af..31a8a00 100644 --- a/src/game/g_scripts.pas +++ b/src/game/g_scripts.pas @@ -38,7 +38,7 @@ var 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; @@ -70,6 +70,11 @@ begin 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; @@ -167,19 +172,25 @@ begin 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; @@ -197,18 +208,16 @@ begin 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;