aboutsummaryrefslogtreecommitdiffstats
path: root/Lua/src/lua/ULuaUsdx.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/ULuaUsdx.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 'Lua/src/lua/ULuaUsdx.pas')
-rw-r--r--Lua/src/lua/ULuaUsdx.pas42
1 files changed, 29 insertions, 13 deletions
diff --git a/Lua/src/lua/ULuaUsdx.pas b/Lua/src/lua/ULuaUsdx.pas
index d5277161..c38eec4c 100644
--- a/Lua/src/lua/ULuaUsdx.pas
+++ b/Lua/src/lua/ULuaUsdx.pas
@@ -49,16 +49,20 @@ function ULuaUsdx_Version(L: Plua_State): Integer; cdecl;
arguments: event_name: string }
function ULuaUsdx_Hook(L: Plua_State): Integer; cdecl;
+{ Usdx.ShutMeDown - no results, no arguments
+ unloads the calling plugin }
+function ULuaUsdx_ShutMeDown(L: Plua_State): Integer; cdecl;
+
const
ULuaUsdx_Lib_f: array [0..3] of lual_reg = (
(name:'Version'; func:ULuaUsdx_Version),
(name:'Time'; func:ULuaUsdx_Time),
(name:'Hook'; func:ULuaUsdx_Hook),
- (name:nil; func:nil)
+ (name:'ShutMeDown'; func:ULuaUsdx_ShutMeDown)
);
implementation
-uses SDL, ULuaCore, UHookableEvent, UConfig;
+uses SDL, ULuaCore, ULuaUtils, UHookableEvent, UConfig;
{ Usdx.Time - returns sdl_time to have time numbers comparable with
ultrastar deluxe ones. no arguments }
@@ -68,7 +72,7 @@ begin
//remove arguments (if any)
top := lua_gettop(L);
- If (top > 0) then
+ if (top > 0) then
lua_pop(L, top);
//push result
@@ -84,7 +88,7 @@ begin
//remove arguments (if any)
top := lua_gettop(L);
- If (top > 0) then
+ if (top > 0) then
lua_pop(L, top);
//push result
@@ -98,19 +102,13 @@ function ULuaUsdx_Hook(L: Plua_State): Integer; cdecl;
var
EventName: String;
FunctionName: String;
- ParentId: Integer;
+ P: TLuaPlugin;
Event: THookableEvent;
begin
EventName := luaL_checkstring(L, 1);
FunctionName := luaL_checkstring(L, 2);
- 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 in ULuaUsdx_Hook');
-
- ParentId := lua_toInteger(L, -1);
+ P := Lua_GetOwner(L);
lua_pop(L, lua_gettop(L)); //clear stack
@@ -119,10 +117,28 @@ begin
Event := LuaCore.GetEventByName(EventName);
if (Event <> nil) then
begin
- Event.Hook(L, ParentId, FunctionName);
+ Event.Hook(L, P.Id, FunctionName);
end
else
luaL_error(L, PChar('event does not exist: ' + EventName));
end;
+function ULuaUsdx_ShutMeDown(L: Plua_State): Integer; cdecl;
+ var
+ top: Integer;
+ P: TLuaPlugin;
+begin
+ Result := 0;
+
+ //remove arguments (if any)
+ top := lua_gettop(L);
+
+ if (top > 0) then
+ lua_pop(L, top);
+
+ P := Lua_GetOwner(L);
+
+ P.ShutMeDown;
+end;
+
end. \ No newline at end of file