"lua-5.1.4/src/lbaselib.c" did not exist on "c653ca2b07a03d3b39e785eb7dd8927c08d2b39a"
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
return globals;
}
}
#endregion
public Lua ()
{
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.lua_pushstring (luaState, "LUAINTERFACE LOADED");
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
panicCallback = new LuaCore.lua_CFunction (PanicCallback);
LuaLib.lua_atpanic (luaState, panicCallback);
}
/*
* CAUTION: NLua.Lua instances can't share the same lua state!
*/
public Lua (LuaCore.lua_State lState)
{
LuaLib.lua_pushstring (lState, "LUAINTERFACE LOADED");
LuaLib.lua_gettable (lState, (int)LuaIndexes.Registry);
if (LuaLib.lua_toboolean (lState, -1)) {
LuaLib.lua_settop (lState, -2);
throw new LuaException ("There is already a NLua.Lua instance associated with this Lua state");
} 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;
LuaLib.lua_pushvalue (lState, (int)LuaIndexes.Globals);
LuaLib.lua_getglobal (lState, "luanet");
LuaLib.lua_pushstring (lState, "getmetatable");
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;
#endregion
public Lua ()
{
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)
Init (luaState);
// We need to keep this in a managed reference so the delegate doesn't get garbage collected
panicCallback = new LuaCore.lua_CFunction (PanicCallback);
LuaLib.lua_atpanic (luaState, panicCallback);
}
/*
* CAUTION: NLua.Lua instances can't share the same lua state!
*/
public Lua (LuaCore.lua_State lState)
{
LuaLib.lua_pushstring (lState, "LUAINTERFACE LOADED");
LuaLib.lua_gettable (lState, (int)LuaIndexes.Registry);
if (LuaLib.lua_toboolean (lState, -1)) {
LuaLib.lua_settop (lState, -2);
throw new LuaException ("There is already a NLua.Lua instance associated with this Lua state");
} else {
luaState = lState;
_StatePassed = true;
LuaLib.lua_settop (luaState, -2);
Init (luaState);
}
}
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 ()
......
......@@ -32,6 +32,5 @@ namespace NLua
{
Registry = (-10000),
Environment = (-10001),
Globals = (-10002)
}
}
\ No newline at end of file
......@@ -135,18 +135,14 @@ namespace NLua
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)
{
lua_pushstring (luaState, name);
LuaCore.lua_gettable (luaState, (int)LuaIndexes.Globals);
{
LuaCore.luanet_getglobal (luaState, name);
}
public static void lua_setglobal (LuaCore.lua_State luaState, string name)
{
lua_pushstring (luaState, name);
lua_insert (luaState, -2);
lua_settable (luaState, (int)LuaIndexes.Globals);
{
LuaCore.luanet_setglobal (luaState, name);
}
public static void lua_settop (LuaCore.lua_State luaState, int newTop)
......@@ -470,5 +466,15 @@ namespace NLua
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