aboutsummaryrefslogtreecommitdiffstats
path: root/Lua/src/lua/ULuaUtils.pas
diff options
context:
space:
mode:
authorwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2009-05-16 13:06:57 +0000
committerwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2009-05-16 13:06:57 +0000
commit1b2346740c8b23f56a29bcbb646266667a911f6b (patch)
treea79112a4ff1c0ec22fca5b7d5234693cc640504a /Lua/src/lua/ULuaUtils.pas
parent0612fdf8fd4badc25e4f1faab24f73c93b690389 (diff)
downloadusdx-1b2346740c8b23f56a29bcbb646266667a911f6b.tar.gz
usdx-1b2346740c8b23f56a29bcbb646266667a911f6b.tar.xz
usdx-1b2346740c8b23f56a29bcbb646266667a911f6b.zip
add Lua_GetOwner to ULuaUtils (function returns plugin by lua state)
use new function in ULuaParty and ULuaUsdx new lua function: Usdx.ShutMeDown to give plugins the ability to unload git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@1732 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r--Lua/src/lua/ULuaUtils.pas35
1 files changed, 32 insertions, 3 deletions
diff --git a/Lua/src/lua/ULuaUtils.pas b/Lua/src/lua/ULuaUtils.pas
index 2bcfea68..de3bd15f 100644
--- a/Lua/src/lua/ULuaUtils.pas
+++ b/Lua/src/lua/ULuaUtils.pas
@@ -33,7 +33,7 @@ interface
{$I switches.inc}
-uses ULua;
+uses ULua, ULuaCore;
{ converts a lua table with a structure like:
* = 1 , * = 4 , * = 5
@@ -42,6 +42,13 @@ uses ULua;
does not pop anything }
function Lua_ToBinInt(L: PLua_State; idx: Integer): Integer;
+{ returns plugin that is the owner of the given state
+ may raise a lua error if the parent id is not found
+ in states registry, if state owner does not exists
+ or is not loaded. So a check for a nil value is not
+ necessary }
+function Lua_GetOwner(L: PLua_State): TLuaPlugin;
+
{ this is a helper in case an evenet owner don't has no use for the results
returns number of popped elements }
function Lua_ClearStack(L: Plua_State): Integer;
@@ -61,7 +68,7 @@ begin
// default: no bits set
Result := 0;
- lua_checkstack(L, 3);
+ lua_checkstack(L, 2);
if (idx < 0) then
dec(idx); // we will push one value before using this
@@ -81,10 +88,32 @@ begin
end;
end;
+{ returns plugin that is the owner of the given state
+ may raise a lua error if the parent id is not found
+ in states registry, if state owner does not exists
+ or is not loaded. So a check for a nil value is not
+ necessary }
+function Lua_GetOwner(L: PLua_State): TLuaPlugin;
+begin
+ lua_checkstack(L, 1);
+
+ lua_getfield (L, LUA_REGISTRYINDEX, '_USDX_STATE_ID');
+ if (not lua_isNumber(L, -1)) then
+ luaL_error(L, 'unable to get _USDX_STATE_ID');
+
+ Result := LuaCore.GetPluginById(lua_toInteger(L, -1));
+
+ lua_pop(L, 1); //< remove state id from stack
+
+ if (Result = nil) then
+ luaL_error(L, '_USDX_STATE_ID has invalid value')
+ else if (Result.Status > psRunning) then
+ luaL_error(L, 'owning plugin is not loaded or already unloaded in Lua_GetOwner');
+end;
+
{ this is a helper in case an evenet owner don't has no use for the results
returns number of popped elements }
function Lua_ClearStack(L: Plua_State): Integer;
- var I: Integer;
begin
Result := lua_gettop(L);
lua_pop(L, Result);