Add a Lua implementation of next_enum_item()

develop
lethosor 2015-11-07 15:22:30 -05:00
parent f8ece1463c
commit 3fb2628921
1 changed files with 17 additions and 0 deletions

@ -1310,6 +1310,18 @@ static int wtype_ipairs(lua_State *state)
return 3; return 3;
} }
static int wtype_next_item(lua_State *state)
{
int first = lua_tointeger(state, lua_upvalueindex(1)),
last = lua_tointeger(state, lua_upvalueindex(2)),
cur = luaL_checkint(state, lua_gettop(state) > 1 ? 2 : 1); // 'self' optional
if (cur < last)
lua_pushinteger(state, cur + 1);
else
lua_pushinteger(state, first);
return 1;
}
static void RenderTypeChildren(lua_State *state, const std::vector<compound_identity*> &children); static void RenderTypeChildren(lua_State *state, const std::vector<compound_identity*> &children);
void LuaWrapper::AssociateId(lua_State *state, int table, int val, const char *name) void LuaWrapper::AssociateId(lua_State *state, int table, int val, const char *name)
@ -1347,6 +1359,11 @@ static void FillEnumKeys(lua_State *state, int ix_meta, int ftable, enum_identit
lua_pushcclosure(state, wtype_ipairs, 3); lua_pushcclosure(state, wtype_ipairs, 3);
lua_setfield(state, ix_meta, "__ipairs"); lua_setfield(state, ix_meta, "__ipairs");
lua_pushinteger(state, eid->getFirstItem());
lua_pushinteger(state, eid->getLastItem());
lua_pushcclosure(state, wtype_next_item, 2);
lua_setfield(state, ftable, "next_item");
lua_pushinteger(state, eid->getFirstItem()); lua_pushinteger(state, eid->getFirstItem());
lua_setfield(state, ftable, "_first_item"); lua_setfield(state, ftable, "_first_item");