int luaL_ref(LuaThread* L) { LuaTable* registry = L->l_G->getRegistry(); LuaValue val = L->stack_.top_[-1]; L->stack_.pop(); if(val.isNil()) return LUA_REFNIL; LuaValue ref1 = registry->get(LuaValue(freelist)); int ref = ref1.isInteger() ? ref1.getInteger() : 0; if (ref != 0) { // any free element? LuaValue temp = registry->get( LuaValue(ref) ); registry->set( LuaValue(freelist), temp ); registry->set( LuaValue(ref), val ); return ref; } else { // no free elements, get a new reference. ref = (int)registry->getLength() + 1; registry->set( LuaValue(ref), val ); return ref; } }
void ScriptProp::initEnumItems() { LuaTable enumTable(-1); enumTable.beginRead(); for (int i = 0; i < enumTable.getLength(); i++) { LuaTable enumItem = enumTable.get(i); enumItem.beginRead(); if (enumItem.getLength() >= 2) { String key = enumItem.get(0).toString(); int val = enumItem.get(1).toInt(); m_enumItems.push_back(std::make_pair(key, val)); } enumItem.endRead(); } enumTable.endRead(); #if 1 for (lua_pushnil(L); lua_next(L,-2); lua_pop(L, 1)) { if (lua_type(L,-2) != LUA_TSTRING) continue; const char* name = lua_tostring(L, -2); if (name[0] == '_') { continue; } if (lua_isnumber(L,-1)) { m_enumItems.push_back(std::make_pair<String,int>(name, lua_tonumber(L,-1))); } } #endif }