public bool MoveNext() { if (tableIndex < 0) { return(false); } if (iterPhase == 0) { LuaNativeMethods.lua_pushnil(table.VariablePointer); iterPhase = 1; } else { LuaNativeMethods.lua_pop(table.VariablePointer, 1); } // var ty = LuaDLL.lua_type(t.L, -1); bool ret = LuaNativeMethods.lua_next(table.VariablePointer, tableIndex) > 0; if (!ret) { iterPhase = 2; } return(ret); }
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)); } }