From 1b2346740c8b23f56a29bcbb646266667a911f6b Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sat, 16 May 2009 13:06:57 +0000 Subject: 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 --- Lua/src/lua/ULuaUsdx.pas | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'Lua/src/lua/ULuaUsdx.pas') 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 -- cgit v1.2.3