Commit 8095f650 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Removing GLOBALINDEX from NLua

parent 751aa03d
Subproject commit c82d8a1bcce31ab57def18dc6ea3804ba13244be Subproject commit 58340188fe1f31ad3a87f7637576518d981005c1
Subproject commit 1c909dbeeb2b36564a0915f55133d132ba05fdb7 Subproject commit b96b5855e7ce151a10ccab1a2f9e9fc1747e2029
...@@ -265,22 +265,7 @@ end ...@@ -265,22 +265,7 @@ end
{ {
luaState = LuaLib.luaL_newstate (); // steffenj: Lua 5.1.1 API change (lua_open is gone) luaState = LuaLib.luaL_newstate (); // steffenj: Lua 5.1.1 API change (lua_open is gone)
LuaLib.luaL_openlibs (luaState); // steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here) LuaLib.luaL_openlibs (luaState); // steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here)
LuaLib.lua_pushstring (luaState, "LUAINTERFACE LOADED"); Init (luaState);
LuaLib.lua_pushboolean (luaState, true);
LuaLib.lua_settable (luaState, (int)LuaIndexes.Registry);
LuaLib.lua_newtable (luaState);
LuaLib.lua_setglobal (luaState, "luanet");
LuaLib.lua_pushvalue (luaState, (int)LuaIndexes.Globals);
LuaLib.lua_getglobal (luaState, "luanet");
LuaLib.lua_pushstring (luaState, "getmetatable");
LuaLib.lua_getglobal (luaState, "getmetatable");
LuaLib.lua_settable (luaState, -3);
LuaLib.lua_replace (luaState, (int)LuaIndexes.Globals);
translator = new ObjectTranslator (this, luaState);
ObjectTranslatorPool.Instance.Add (luaState, translator);
LuaLib.lua_replace (luaState, (int)LuaIndexes.Globals);
LuaLib.luaL_dostring (luaState, Lua.init_luanet); // steffenj: lua_dostring renamed to luaL_dostring
// We need to keep this in a managed reference so the delegate doesn't get garbage collected // We need to keep this in a managed reference so the delegate doesn't get garbage collected
panicCallback = new LuaCore.lua_CFunction (PanicCallback); panicCallback = new LuaCore.lua_CFunction (PanicCallback);
LuaLib.lua_atpanic (luaState, panicCallback); LuaLib.lua_atpanic (luaState, panicCallback);
...@@ -298,24 +283,32 @@ end ...@@ -298,24 +283,32 @@ end
LuaLib.lua_settop (lState, -2); LuaLib.lua_settop (lState, -2);
throw new LuaException ("There is already a NLua.Lua instance associated with this Lua state"); throw new LuaException ("There is already a NLua.Lua instance associated with this Lua state");
} else { } else {
LuaLib.lua_settop (lState, -2);
LuaLib.lua_pushstring (lState, "LUAINTERFACE LOADED");
LuaLib.lua_pushboolean (lState, true);
LuaLib.lua_settable (lState, (int)LuaIndexes.Registry);
luaState = lState; luaState = lState;
LuaLib.lua_pushvalue (lState, (int)LuaIndexes.Globals); _StatePassed = true;
LuaLib.lua_getglobal (lState, "luanet"); LuaLib.lua_settop (luaState, -2);
LuaLib.lua_pushstring (lState, "getmetatable"); Init (luaState);
LuaLib.lua_getglobal (lState, "getmetatable"); }
LuaLib.lua_settable (lState, -3);
LuaLib.lua_replace (lState, (int)LuaIndexes.Globals);
translator = new ObjectTranslator (this, luaState);
ObjectTranslatorPool.Instance.Add (luaState, translator);
LuaLib.lua_replace (lState, (int)LuaIndexes.Globals);
LuaLib.luaL_dostring (lState, Lua.init_luanet); // steffenj: lua_dostring renamed to luaL_dostring
} }
_StatePassed = true; void Init (LuaCore.lua_State luaState)
{
LuaLib.lua_pushstring (luaState, "LUAINTERFACE LOADED");
LuaLib.lua_pushboolean (luaState, true);
LuaLib.lua_settable (luaState, (int)LuaIndexes.Registry);
if (_StatePassed == false) {
LuaLib.lua_newtable (luaState);
LuaLib.lua_setglobal (luaState, "luanet");
}
LuaLib.luanet_pushglobaltable (luaState);
LuaLib.lua_getglobal (luaState, "luanet");
LuaLib.lua_pushstring (luaState, "getmetatable");
LuaLib.lua_getglobal (luaState, "getmetatable");
LuaLib.lua_settable (luaState, -3);
LuaLib.luanet_popglobaltable (luaState);
translator = new ObjectTranslator (this, luaState);
ObjectTranslatorPool.Instance.Add (luaState, translator);
LuaLib.luanet_popglobaltable (luaState);
LuaLib.luaL_dostring (luaState, Lua.init_luanet);
} }
public void Close () public void Close ()
......
...@@ -32,6 +32,5 @@ namespace NLua ...@@ -32,6 +32,5 @@ namespace NLua
{ {
Registry = (-10000), Registry = (-10000),
Environment = (-10001), Environment = (-10001),
Globals = (-10002)
} }
} }
\ No newline at end of file
...@@ -135,18 +135,14 @@ namespace NLua ...@@ -135,18 +135,14 @@ namespace NLua
return LuaCore.lua_pcall (luaState, 0, -1, 0); return LuaCore.lua_pcall (luaState, 0, -1, 0);
} }
// steffenj: END Lua 5.1.1 API change (lua_dofile now in LuaLib as luaL_dofile)
public static void lua_getglobal (LuaCore.lua_State luaState, string name) public static void lua_getglobal (LuaCore.lua_State luaState, string name)
{ {
lua_pushstring (luaState, name); LuaCore.luanet_getglobal (luaState, name);
LuaCore.lua_gettable (luaState, (int)LuaIndexes.Globals);
} }
public static void lua_setglobal (LuaCore.lua_State luaState, string name) public static void lua_setglobal (LuaCore.lua_State luaState, string name)
{ {
lua_pushstring (luaState, name); LuaCore.luanet_setglobal (luaState, name);
lua_insert (luaState, -2);
lua_settable (luaState, (int)LuaIndexes.Globals);
} }
public static void lua_settop (LuaCore.lua_State luaState, int newTop) public static void lua_settop (LuaCore.lua_State luaState, int newTop)
...@@ -470,5 +466,15 @@ namespace NLua ...@@ -470,5 +466,15 @@ namespace NLua
return LuaCore.luanet_gettag (); return LuaCore.luanet_gettag ();
} }
public static void luanet_pushglobaltable (LuaCore.lua_State luaState)
{
LuaCore.luanet_pushglobaltable (luaState);
}
public static void luanet_popglobaltable (LuaCore.lua_State luaState)
{
LuaCore.luanet_popglobaltable (luaState);
}
} }
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment