aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorbrian-ch <brian-ch@b956fd51-792f-4845-bead-9b4dfca2ff2c>2014-06-12 20:27:54 +0000
committerbrian-ch <brian-ch@b956fd51-792f-4845-bead-9b4dfca2ff2c>2014-06-12 20:27:54 +0000
commitef6d6c7b8cac6041376acaf004a268f263ac0492 (patch)
tree2f3805cf7df36af88bb0f844aaff63891e3e21af /src/lua
parent8c30f8b2ceb95e1286c76e162913042e08df0996 (diff)
downloadusdx-ef6d6c7b8cac6041376acaf004a268f263ac0492.tar.gz
usdx-ef6d6c7b8cac6041376acaf004a268f263ac0492.tar.xz
usdx-ef6d6c7b8cac6041376acaf004a268f263ac0492.zip
Fix for lua5.2
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@3070 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/ULuaCore.pas80
1 files changed, 19 insertions, 61 deletions
diff --git a/src/lua/ULuaCore.pas b/src/lua/ULuaCore.pas
index a0398eb4..ea57b68b 100644
--- a/src/lua/ULuaCore.pas
+++ b/src/lua/ULuaCore.pas
@@ -475,67 +475,19 @@ end;
procedure TLuaCore.PrepareState(L: Plua_State);
begin
// load basic lib functionality
- lua_pushcfunction(L, luaopen_base);
- lua_call(L, 0, 0);
- lua_pop(L, lua_gettop(L)); // pop the results
+ lual_openLibs(L);
+ lua_pop(L,1);
- // load module functionality
- lua_pushcfunction(L, luaopen_package);
- lua_call(L, 0, 0);
- lua_pop(L, lua_gettop(L)); // pop the results
-
- { adds the loader for the other standard lib to package.preload table
- plugins can call e.g. require('math') if they need math functionality }
-
- // we need 3 free stack slots
- lua_checkstack(L, 3);
-
- // get package table
- lua_getglobal (L, PChar('package'));
-
- // get package.preload table
- lua_getfield (L, -1, PChar('preload'));
-
- {**** add string lib }
-
- // push loader function
- lua_pushcfunction(L, luaopen_string);
-
- // set package.preload.x loader
- lua_setfield (L, -2, PChar('string'));
-
- {**** add table lib }
-
- // push loader function
- lua_pushcfunction(L, luaopen_table);
-
- // set package.preload.x loader
- lua_setfield (L, -2, PChar('table'));
-
- {**** add math lib }
-
- // push loader function
- lua_pushcfunction(L, luaopen_math);
-
- // set package.preload.x loader
- lua_setfield (L, -2, PChar('math'));
-
- {**** add os lib }
-
- // push loader function
- lua_pushcfunction(L, luaopen_os);
-
- // set package.preload.x loader
- lua_setfield (L, -2, PChar('os'));
-
- //pop package.preload table from stack
- lua_pop(L, 1);
-
- // get package.loaders table
- lua_getfield (L, -1, PChar('loaders'));
+ // get package.searchers (former package.loaders) table
+ lua_getGlobal (L, PChar('package'));
+{$IF LUA_VERSION_NUM >= 502}
+ lua_getfield(L,-1,PChar('searchers'));
+{$ELSE}
+ lua_getfield(L,-1,PChar('loaders'));
+{$IFEND}
{**** Move C-Library and all-in-one module loader backwards,
- slot 3 is free now }
+ slot 3 is free now }
// get package.loaders[4] function
lua_pushinteger(L, 5); // push new index
lua_pushinteger(L, 4); // push old index
@@ -651,7 +603,12 @@ begin
if (not lua_isnoneornil(L, lua_upvalueindex(1))) then
begin
Id := lua_ToInteger(L, lua_upvalueindex(1));
-
+{$IF LUA_VERSION_NUM >= 502}
+ // set module table as a field of the global Usdx
+ lua_getglobal(L,Pchar('Usdx'));
+ luaL_register(L, PChar(LuaCore.Modules[Id].Name), @LuaCore.Modules[Id].Functions[0]);
+ lua_setfield(L, -2, PChar(LuaCore.Modules[Id].Name));
+{$ELSE}
luaL_register(L, PChar('Usdx.' + LuaCore.Modules[Id].Name), @LuaCore.Modules[Id].Functions[0]);
// set the modules table as global "modulename"
@@ -661,7 +618,7 @@ begin
// no we net to push the table again to return it
lua_getglobal(L, PChar(LuaCore.Modules[Id].Name));
-
+{$IFEND}
Result := 1; // return table
end
else
@@ -1013,6 +970,7 @@ begin
// move through parameters
while (lua_getTop(L) >= 1) do
begin
+ lua_checkstack(L,1);
// get luas require function
lua_getglobal(L, PChar('_require'));
@@ -1024,4 +982,4 @@ begin
end;
end;
-end. \ No newline at end of file
+end. \ No newline at end of file