* Make a metatable with most common fields, and an empty table for UPVAL_FIELDTABLE. */
| 1146 | * Make a metatable with most common fields, and an empty table for UPVAL_FIELDTABLE. |
| 1147 | */ |
| 1148 | void LuaWrapper::MakeMetatable(lua_State *state, const type_identity *type, const char *kind) |
| 1149 | { |
| 1150 | int base = lua_gettop(state); |
| 1151 | lua_newtable(state); // metatable |
| 1152 | |
| 1153 | lua_pushstring(state, type->getFullName().c_str()); |
| 1154 | lua_setfield(state, base+1, "__metatable"); |
| 1155 | |
| 1156 | lua_pushlightuserdata(state, const_cast<type_identity*>(type)); |
| 1157 | lua_rawsetp(state, base+1, &DFHACK_IDENTITY_FIELD_TOKEN); |
| 1158 | |
| 1159 | LookupInTable(state, const_cast<type_identity*>(type), &DFHACK_TYPEID_TABLE_TOKEN); |
| 1160 | if (lua_isnil(state, -1)) |
| 1161 | { |
| 1162 | // Copy the string from __metatable if no real type |
| 1163 | lua_pop(state, 1); |
| 1164 | lua_getfield(state, base+1, "__metatable"); |
| 1165 | } |
| 1166 | lua_setfield(state, base+1, "_type"); |
| 1167 | |
| 1168 | lua_pushstring(state, kind); |
| 1169 | lua_setfield(state, base+1, "_kind"); |
| 1170 | |
| 1171 | // Create the field table |
| 1172 | lua_newtable(state); |
| 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * Enable a metafield by injecting an entry into a UPVAL_FIELDTABLE. |
nothing calls this directly
no test coverage detected