"...System.Reflection.Emit.4.3.0/vscode:/vscode.git/clone" did not exist on "f493fd0616e2829a76d8f85d6d3007ff74f20da6"
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
...@@ -259,63 +259,56 @@ end ...@@ -259,63 +259,56 @@ end
return globals; return globals;
} }
} }
#endregion #endregion
public Lua () public Lua ()
{ {
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); // We need to keep this in a managed reference so the delegate doesn't get garbage collected
LuaLib.lua_settable (luaState, (int)LuaIndexes.Registry); panicCallback = new LuaCore.lua_CFunction (PanicCallback);
LuaLib.lua_newtable (luaState); LuaLib.lua_atpanic (luaState, panicCallback);
LuaLib.lua_setglobal (luaState, "luanet"); }
LuaLib.lua_pushvalue (luaState, (int)LuaIndexes.Globals);
LuaLib.lua_getglobal (luaState, "luanet"); /*
LuaLib.lua_pushstring (luaState, "getmetatable"); * CAUTION: NLua.Lua instances can't share the same lua state!
LuaLib.lua_getglobal (luaState, "getmetatable"); */
LuaLib.lua_settable (luaState, -3); public Lua (LuaCore.lua_State lState)
LuaLib.lua_replace (luaState, (int)LuaIndexes.Globals); {
translator = new ObjectTranslator (this, luaState); LuaLib.lua_pushstring (lState, "LUAINTERFACE LOADED");
ObjectTranslatorPool.Instance.Add (luaState, translator); LuaLib.lua_gettable (lState, (int)LuaIndexes.Registry);
LuaLib.lua_replace (luaState, (int)LuaIndexes.Globals);
LuaLib.luaL_dostring (luaState, Lua.init_luanet); // steffenj: lua_dostring renamed to luaL_dostring if (LuaLib.lua_toboolean (lState, -1)) {
LuaLib.lua_settop (lState, -2);
// We need to keep this in a managed reference so the delegate doesn't get garbage collected throw new LuaException ("There is already a NLua.Lua instance associated with this Lua state");
panicCallback = new LuaCore.lua_CFunction (PanicCallback); } else {
LuaLib.lua_atpanic (luaState, panicCallback); luaState = lState;
} _StatePassed = true;
LuaLib.lua_settop (luaState, -2);
/* Init (luaState);
* CAUTION: NLua.Lua instances can't share the same lua state! }
*/ }
public Lua (LuaCore.lua_State lState)
{ void Init (LuaCore.lua_State luaState)
LuaLib.lua_pushstring (lState, "LUAINTERFACE LOADED"); {
LuaLib.lua_gettable (lState, (int)LuaIndexes.Registry); LuaLib.lua_pushstring (luaState, "LUAINTERFACE LOADED");
LuaLib.lua_pushboolean (luaState, true);
if (LuaLib.lua_toboolean (lState, -1)) { LuaLib.lua_settable (luaState, (int)LuaIndexes.Registry);
LuaLib.lua_settop (lState, -2); if (_StatePassed == false) {
throw new LuaException ("There is already a NLua.Lua instance associated with this Lua state"); LuaLib.lua_newtable (luaState);
} else { LuaLib.lua_setglobal (luaState, "luanet");
LuaLib.lua_settop (lState, -2); }
LuaLib.lua_pushstring (lState, "LUAINTERFACE LOADED"); LuaLib.luanet_pushglobaltable (luaState);
LuaLib.lua_pushboolean (lState, true); LuaLib.lua_getglobal (luaState, "luanet");
LuaLib.lua_settable (lState, (int)LuaIndexes.Registry); LuaLib.lua_pushstring (luaState, "getmetatable");
luaState = lState; LuaLib.lua_getglobal (luaState, "getmetatable");
LuaLib.lua_pushvalue (lState, (int)LuaIndexes.Globals); LuaLib.lua_settable (luaState, -3);
LuaLib.lua_getglobal (lState, "luanet"); LuaLib.luanet_popglobaltable (luaState);
LuaLib.lua_pushstring (lState, "getmetatable"); translator = new ObjectTranslator (this, luaState);
LuaLib.lua_getglobal (lState, "getmetatable"); ObjectTranslatorPool.Instance.Add (luaState, translator);
LuaLib.lua_settable (lState, -3); LuaLib.luanet_popglobaltable (luaState);
LuaLib.lua_replace (lState, (int)LuaIndexes.Globals); LuaLib.luaL_dostring (luaState, Lua.init_luanet);
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;
} }
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