MCPcopy Create free account
hub / github.com/DFHack/dfhack / AttachEnumKeys

Method AttachEnumKeys

library/LuaWrapper.cpp:1296–1321  ·  view source on GitHub ↗

* If ienum refers to a valid enum, attach its keys to UPVAL_FIELDTABLE, * and the enum itself to the _enum metafield. Pushes the key table on the stack */

Source from the content-addressed store, hash-verified

1294 * and the enum itself to the _enum metafield. Pushes the key table on the stack
1295 */
1296void LuaWrapper::AttachEnumKeys(lua_State *state, int meta_idx, int ftable_idx, const type_identity *ienum)
1297{
1298 EnableMetaField(state, ftable_idx, "_enum");
1299
1300 LookupInTable(state, const_cast<type_identity*>(ienum), &DFHACK_TYPEID_TABLE_TOKEN);
1301 lua_setfield(state, meta_idx, "_enum");
1302
1303 LookupInTable(state, const_cast<type_identity*>(ienum), &DFHACK_ENUM_TABLE_TOKEN);
1304
1305 if (!lua_isnil(state, -1))
1306 {
1307 lua_dup(state);
1308 lua_newtable(state);
1309 lua_swap(state);
1310 lua_setfield(state, -2, "__index");
1311 lua_setmetatable(state, ftable_idx);
1312 }
1313 else
1314 {
1315 lua_pop(state, 1);
1316 lua_rawgetp(state, LUA_REGISTRYINDEX, &DFHACK_EMPTY_TABLE_TOKEN);
1317 }
1318
1319 lua_dup(state);
1320 lua_setfield(state, meta_idx, "_index_table");
1321}
1322
1323static void BuildTypeMetatable(lua_State *state, const type_identity *type)
1324{

Callers

nothing calls this directly

Calls 6

LookupInTableFunction · 0.85
lua_setfieldFunction · 0.85
lua_dupFunction · 0.85
lua_swapFunction · 0.85
lua_setmetatableFunction · 0.85
lua_rawgetpFunction · 0.85

Tested by

no test coverage detected