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

Function MakePrimitiveMetatable

library/LuaTypes.cpp:1609–1639  ·  view source on GitHub ↗

* Make a primitive-style metatable */

Source from the content-addressed store, hash-verified

1607 * Make a primitive-style metatable
1608 */
1609static void MakePrimitiveMetatable(lua_State *state, const type_identity *type)
1610{
1611 int base = lua_gettop(state);
1612
1613 MakeMetatable(state, type, "primitive");
1614
1615 SetPtrMethods(state, base+1, base+2);
1616
1617 // Index the fields
1618 lua_newtable(state);
1619
1620 if (type->type() != IDTYPE_OPAQUE)
1621 {
1622 EnableMetaField(state, base+2, "value", const_cast<type_identity*>(type));
1623 AssociateId(state, base+3, 1, "value");
1624
1625 EnableMetaField(state, base+2, "ref_target", NULL);
1626 }
1627
1628 // Add the iteration metamethods
1629 PushStructMethod(state, base+1, base+3, meta_struct_next);
1630 SetPairsMethod(state, base+1, "__pairs");
1631 lua_pushnil(state);
1632 SetPairsMethod(state, base+1, "__ipairs");
1633
1634 lua_setfield(state, base+1, "_index_table");
1635
1636 // Add the indexing metamethods
1637 SetStructMethod(state, base+1, base+2, meta_primitive_index, "__index");
1638 SetStructMethod(state, base+1, base+2, meta_primitive_newindex, "__newindex");
1639}
1640
1641static void AddContainerMethodFun(lua_State *state, int meta_idx, int field_idx,
1642 lua_CFunction function, const char *name,

Callers 1

build_metatableMethod · 0.85

Calls 4

lua_gettopFunction · 0.85
lua_pushnilFunction · 0.85
lua_setfieldFunction · 0.85
typeMethod · 0.45

Tested by

no test coverage detected