public object GetObject(string key) { LuaNativeMethods.lua_pushglobaltable(statePointer); object o = GetObject(key.Split(new char[] { '.' })); LuaNativeMethods.lua_pop(statePointer, 1); return(o); }
public static int Import(IntPtr ptr) { try { LuaNativeMethods.luaL_checktype(ptr, 1, LuaTypes.TYPE_STRING); string str = LuaNativeMethods.lua_tostring(ptr, 1); string[] ns = str.Split('.'); LuaNativeMethods.lua_pushglobaltable(ptr); for (int n = 0; n < ns.Length; n++) { LuaNativeMethods.lua_getfield(ptr, -1, ns[n]); if (!LuaNativeMethods.lua_istable(ptr, -1)) { return(LuaObject.Error(ptr, "expect {0} is type table", ns)); } LuaNativeMethods.lua_remove(ptr, -2); } LuaNativeMethods.lua_pushnil(ptr); while (LuaNativeMethods.lua_next(ptr, -2) != 0) { string key = LuaNativeMethods.lua_tostring(ptr, -2); LuaNativeMethods.lua_getglobal(ptr, key); if (!LuaNativeMethods.lua_isnil(ptr, -1)) { LuaNativeMethods.lua_pop(ptr, 1); return(LuaObject.Error(ptr, "{0} had existed, import can't overload it.", key)); } LuaNativeMethods.lua_pop(ptr, 1); LuaNativeMethods.lua_setglobal(ptr, key); } LuaNativeMethods.lua_pop(ptr, 1); LuaObject.PushValue(ptr, true); return(1); } catch (Exception e) { return(LuaObject.Error(ptr, e)); } }
public static void NewTypeTable(IntPtr ptr, string name) { string[] subt = name.Split('.'); LuaNativeMethods.lua_pushglobaltable(ptr); foreach (string t in subt) { LuaNativeMethods.lua_pushstring(ptr, t); LuaNativeMethods.lua_rawget(ptr, -2); if (LuaNativeMethods.lua_isnil(ptr, -1)) { LuaNativeMethods.lua_pop(ptr, 1); LuaNativeMethods.lua_createtable(ptr, 0, 0); LuaNativeMethods.lua_pushstring(ptr, t); LuaNativeMethods.lua_pushvalue(ptr, -2); LuaNativeMethods.lua_rawset(ptr, -4); } LuaNativeMethods.lua_remove(ptr, -2); } }
public void SetObject(string key, object v) { LuaNativeMethods.lua_pushglobaltable(statePointer); SetObject(key.Split(new char[] { '.' }), v); LuaNativeMethods.lua_pop(statePointer, 1); }