aboutsummaryrefslogtreecommitdiffstats
path: root/Lua/src/lua/ULuaUsdx.pas
diff options
context:
space:
mode:
authorwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2009-04-20 12:47:39 +0000
committerwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2009-04-20 12:47:39 +0000
commiteab0940bcf7577a9542b474848ee376c581d898c (patch)
treeedd09b7e00a6a8d29db5e9ae9307971d6c4809a5 /Lua/src/lua/ULuaUsdx.pas
parent6a44ff7dc1154b6bc5cf9ef250b536c5fc11519e (diff)
downloadusdx-eab0940bcf7577a9542b474848ee376c581d898c.tar.gz
usdx-eab0940bcf7577a9542b474848ee376c581d898c.tar.xz
usdx-eab0940bcf7577a9542b474848ee376c581d898c.zip
hookable event nearly finished(unhook function missing)
plugin Id now written to the lua states registry Usdx.Version added, Usdx.Hook added git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@1689 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r--Lua/src/lua/ULuaUsdx.pas65
1 files changed, 59 insertions, 6 deletions
diff --git a/Lua/src/lua/ULuaUsdx.pas b/Lua/src/lua/ULuaUsdx.pas
index 558a47cd..4bbb64ea 100644
--- a/Lua/src/lua/ULuaUsdx.pas
+++ b/Lua/src/lua/ULuaUsdx.pas
@@ -37,19 +37,28 @@ uses ULua;
{ some basic lua c functions from usdx table }
-{ usdx.time - returns sdl_time to have time numbers comparable with
- ultrastar delux ones. No Arguments }
+{ Usdx.Time - returns sdl_time to have time numbers comparable with
+ ultrastar delux ones. no arguments }
function ULuaUsdx_Time(L: Plua_State): Integer; cdecl;
-function ULuaUsdx_(L: Plua_State): Integer; cdecl;
+
+{ Usdx.Version - returns Usdx version string (the same that US_Version
+ language-constant does). no arguments }
+function ULuaUsdx_Version(L: Plua_State): Integer; cdecl;
+
+{ Usdx.Hook - returns an hook table with name and Unhook function
+ arguments: event_name: string }
+function ULuaUsdx_Hook(L: Plua_State): Integer; cdecl;
const
- ULuaUsdx_Lib_f: array [0..1] of lual_reg = (
+ 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)
);
implementation
-uses SDL;
+uses SDL, ULuaCore, UHookableEvent, UConfig;
function ULuaUsdx_Time(L: Plua_State): Integer; cdecl;
var top: Integer;
@@ -65,9 +74,53 @@ begin
Result := 1; //one result
end;
-function ULuaUsdx_(L: Plua_State): Integer; cdecl;
+{ Usdx.Version - returns Usdx version string (the same that US_Version
+ language-constant does). no arguments }
+function ULuaUsdx_Version(L: Plua_State): Integer; cdecl;
+ var top: Integer;
begin
+ //remove arguments (if any)
+ top := lua_gettop(L);
+
+ If (top > 0) then
+ lua_pop(L, top);
+
+ //push result
+ lua_pushstring(L, PChar(USDXVersionStr()));
+ Result := 1; //one result
+end;
+
+{ Usdx.Hook - returns an hook table with name and Unhook function
+ arguments: event_name: string; function_name: string }
+function ULuaUsdx_Hook(L: Plua_State): Integer; cdecl;
+var
+ EventName: String;
+ FunctionName: String;
+ ParentId: Integer;
+ 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);
+
+ lua_pop(L, lua_gettop(L)); //clear stack
+
+ Result := 1;
+ Event := LuaCore.GetEventByName(EventName);
+ if (Event <> nil) then
+ begin
+ Event.Hook(L, ParentId, FunctionName);
+ end
+ else
+ luaL_error(L, PChar('event does not exist: ' + EventName));
end;
end. \ No newline at end of file