Add index_enum, ref_target

develop
lethosor 2023-08-12 22:12:45 -04:00
parent 396b2d7832
commit 574fa08747
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
2 changed files with 29 additions and 6 deletions

@ -1365,6 +1365,13 @@ static void IndexFields(lua_State *state, int base, struct_identity *pstruct, in
} }
} }
static void PushTypeIdentity(lua_State *state, const type_identity *id)
{
lua_rawgetp(state, LUA_REGISTRYINDEX, &DFHACK_TYPEID_TABLE_TOKEN);
lua_rawgetp(state, -1, id);
lua_remove(state, -2); // TYPEID_TABLE
}
static void PushFieldInfoSubTable(lua_State *state, const struct_field_info *field) static void PushFieldInfoSubTable(lua_State *state, const struct_field_info *field)
{ {
if (!field) { if (!field) {
@ -1384,15 +1391,19 @@ static void PushFieldInfoSubTable(lua_State *state, const struct_field_info *fie
lua_pushlightuserdata(state, field->type); lua_pushlightuserdata(state, field->type);
lua_setfield(state, -2, "type_identity"); lua_setfield(state, -2, "type_identity");
lua_pushstring(state, "type"); PushTypeIdentity(state, field->type);
lua_rawgetp(state, LUA_REGISTRYINDEX, &DFHACK_TYPEID_TABLE_TOKEN); lua_setfield(state, -2, "type");
lua_rawgetp(state, -1, field->type);
lua_remove(state, -2); // TYPEID_TABLE
lua_settable(state, -3);
} }
if (field->extra) { if (field->extra) {
// TODO: index_enum, ref_target if (field->extra->index_enum) {
PushTypeIdentity(state, field->extra->index_enum);
lua_setfield(state, -2, "index_enum");
}
if (field->extra->ref_target) {
PushTypeIdentity(state, field->extra->ref_target);
lua_setfield(state, -2, "ref_target");
}
if (field->extra->union_tag_field) { if (field->extra->union_tag_field) {
Lua::TableInsert(state, "union_tag_field", field->extra->union_tag_field); Lua::TableInsert(state, "union_tag_field", field->extra->union_tag_field);
} }

@ -52,6 +52,18 @@ function test.nonexistent()
end) end)
end end
function test.count()
expect.eq(df.unit._fields.relationship_ids.count, 10)
end
function test.index_enum()
expect.eq(df.unit._fields.relationship_ids.index_enum, df.unit_relationship_type)
end
function test.ref_target()
expect.eq(df.unit._fields.hist_figure_id.ref_target, df.historical_figure)
end
function test.readonly() function test.readonly()
expect.error_match(READONLY_MSG, function() expect.error_match(READONLY_MSG, function()
df.coord._fields.x = 'foo' df.coord._fields.x = 'foo'