aboutsummaryrefslogtreecommitdiffstats
path: root/Lua/src/lua/ULuaCore.pas
diff options
context:
space:
mode:
authorwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2009-05-04 07:29:52 +0000
committerwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2009-05-04 07:29:52 +0000
commit14e96597c65a2402ee4ddc068ff08c7659123a1d (patch)
treeebefcbd5ec72570f68bb7b043365b3d6fb93dd6b /Lua/src/lua/ULuaCore.pas
parent2449e4a979c23addcc9110a4dc876d9acd761005 (diff)
downloadusdx-14e96597c65a2402ee4ddc068ff08c7659123a1d.tar.gz
usdx-14e96597c65a2402ee4ddc068ff08c7659123a1d.tar.xz
usdx-14e96597c65a2402ee4ddc068ff08c7659123a1d.zip
old lua test stuff by hawkear removed or commented
new function: Party.SetWinner sets winner of current round new unit ULuaUtils w/ some functions that are or may become useful moved Lua_ClearStack and Lua_ToBinInt to ULuaUtils added first hooks (have a look at hooks.txt in game/plugins until documentation is finished) lua module for TextGl written and finished lua testfile (game/scripts/main.lua) ported to new interface, see game/plugins/LuaTest.usdx git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@1709 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r--Lua/src/lua/ULuaCore.pas30
1 files changed, 28 insertions, 2 deletions
diff --git a/Lua/src/lua/ULuaCore.pas b/Lua/src/lua/ULuaCore.pas
index 403709dd..5c6f2463 100644
--- a/Lua/src/lua/ULuaCore.pas
+++ b/Lua/src/lua/ULuaCore.pas
@@ -117,6 +117,8 @@ type
EventHandles: Array of String; //< Index is Events handle, value is events name. if length(value) is 0 handle is considered unregistred
Plugins: Array of TLuaPlugin;
+
+ eLoadingFinished: THookableEvent;
protected
Modules: Array of TLuaModule; //< modules that has been registred, has to be proctected because fucntions of this unit need to get access
@@ -125,6 +127,8 @@ type
constructor Create;
destructor Destroy;
+ procedure LoadPlugins; //< calls LoadPlugin w/ Plugindir and LoadingFinished Eventchain
+
procedure BrowseDir(Dir: WideString); //< searches for files w/ extension .usdx in the specified dir and tries to load them w/ lua
procedure LoadPlugin(Filename: WideString); //< tries to load filename w/ lua and creates the default usdx lua environment for the plugins state
@@ -177,7 +181,7 @@ var
LuaCore: TLuaCore;
implementation
-uses ULog, UPlatform, ULuaUsdx;
+uses ULog, UPlatform, ULuaUsdx, UMain;
constructor TLuaCore.Create;
begin
@@ -185,6 +189,8 @@ begin
//init EventList w/ nil
EventList := nil;
+
+ eLoadingFinished := nil;
end;
destructor TLuaCore.Destroy;
@@ -208,6 +214,18 @@ begin
inherited;
end;
+{ calls BrowseDir w/ plugin dir and LoadingFinished eventchain }
+procedure TLuaCore.LoadPlugins;
+begin
+ // we have to create event here, because in create it can
+ // not be registred, because LuaCore is no assigned
+ if (not Assigned(eLoadingFinished)) then
+ eLoadingFinished := THookableEvent.Create('Usdx.LoadingFinished');
+
+ BrowseDir(PluginPath);
+ eLoadingFinished.CallHookChain(false);
+end;
+
{ searches for files w/ extension .usdx in the specified
dir and tries to load them w/ lua }
procedure TLuaCore.BrowseDir(Dir: WideString);
@@ -564,7 +582,15 @@ begin
Id := lua_ToInteger(L, lua_upvalueindex(1));
luaL_register(L, PChar('Usdx.' + LuaCore.Modules[Id].Name), @LuaCore.Modules[Id].Functions[0]);
-
+
+ // set the modules table as global "modulename"
+ // so it can be accessed either by Usdx.modulename.x() or
+ // by modulename.x()
+ lua_setglobal(L, PChar(LuaCore.Modules[Id].Name));
+
+ // no we net to push the table again to return it
+ lua_getglobal(L, PChar(LuaCore.Modules[Id].Name));
+
Result := 1; //return table
end
else