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

Function GetAdHocMetatable

library/LuaTypes.cpp:1786–1824  ·  view source on GitHub ↗

* Construct a metatable for an object type folded into the field descriptor. * This is done to reduce compile-time symbol table bloat due to templates. */

Source from the content-addressed store, hash-verified

1784 * This is done to reduce compile-time symbol table bloat due to templates.
1785 */
1786static void GetAdHocMetatable(lua_State *state, const struct_field_info *field)
1787{
1788 lua_pushlightuserdata(state, (void*)field);
1789
1790 if (!LookupTypeInfo(state, true))
1791 {
1792 switch (field->mode)
1793 {
1794 case struct_field_info::CONTAINER:
1795 {
1796 auto ctype = (container_identity*)field->type;
1797 MakeContainerMetatable(state, ctype, ctype->getItemType(), -1, field->extra ? field->extra->index_enum : nullptr);
1798 break;
1799 }
1800
1801 case struct_field_info::STATIC_STRING:
1802 MakeContainerMetatable(state, &df::buffer_container_identity::base_instance,
1803 &df::identity_traits<char>::identity, field->count, NULL);
1804 break;
1805
1806 case struct_field_info::STATIC_ARRAY:
1807 MakeContainerMetatable(state, &df::buffer_container_identity::base_instance,
1808 field->type, field->count, field->extra ? field->extra->index_enum : nullptr);
1809 break;
1810
1811 case struct_field_info::STL_VECTOR_PTR:
1812 MakeContainerMetatable(state, &df::identity_traits<std::vector<void*> >::identity,
1813 field->type, -1, field->extra ? field->extra->index_enum : nullptr);
1814 break;
1815
1816 default:
1817 luaL_error(state, "Invalid ad-hoc field: %d", field->mode);
1818 }
1819
1820 lua_pop(state, 1);
1821
1822 SaveTypeInfo(state, (void*)field);
1823 }
1824}
1825
1826void LuaWrapper::push_adhoc_pointer(lua_State *state, void *ptr, const type_identity *target)
1827{

Callers 2

read_fieldFunction · 0.85
field_referenceFunction · 0.85

Calls 3

lua_pushlightuserdataFunction · 0.85
MakeContainerMetatableFunction · 0.85
luaL_errorFunction · 0.85

Tested by

no test coverage detected