implement df-other-vectors-type for lua

develop
Ben Lubar 2020-04-28 13:55:34 -05:00
parent 7cf9624de9
commit 6c20fe4c80
No known key found for this signature in database
GPG Key ID: 92939677AB59EDA4
2 changed files with 40 additions and 0 deletions

@ -1422,6 +1422,28 @@ void struct_identity::build_metatable(lua_State *state)
SetPtrMethods(state, base+1, base+2);
}
void other_vectors_identity::build_metatable(lua_State *state)
{
int base = lua_gettop(state);
MakeFieldMetatable(state, this, meta_struct_index, meta_struct_newindex);
EnableMetaField(state, base+2, "_enum");
LookupInTable(state, index_enum, &DFHACK_TYPEID_TABLE_TOKEN);
lua_setfield(state, base+1, "_enum");
auto keys = &index_enum->getKeys()[-index_enum->getFirstItem()];
for (int64_t i = 0; i < index_enum->getLastItem(); i++)
{
lua_getfield(state, base+2, keys[i]);
lua_rawseti(state, base+2, int(i));
}
SetStructMethod(state, base+1, base+2, meta_struct_field_reference, "_field");
SetPtrMethods(state, base+1, base+2);
}
void global_identity::build_metatable(lua_State *state)
{
int base = lua_gettop(state);

@ -334,6 +334,23 @@ namespace DFHack
virtual identity_type type() { return IDTYPE_UNION; }
};
class DFHACK_EXPORT other_vectors_identity : public struct_identity {
enum_identity *index_enum;
public:
other_vectors_identity(size_t size, TAllocateFn alloc,
compound_identity *scope_parent, const char *dfhack_name,
struct_identity *parent, const struct_field_info *fields,
enum_identity *index_enum) :
struct_identity(size, alloc, scope_parent, dfhack_name, parent, fields),
index_enum(index_enum)
{}
enum_identity *getIndexEnum() { return index_enum; }
virtual void build_metatable(lua_State *state);
};
#ifdef _MSC_VER
typedef void *virtual_ptr;
#else
@ -465,6 +482,7 @@ namespace df
using DFHack::global_identity;
using DFHack::struct_identity;
using DFHack::union_identity;
using DFHack::other_vectors_identity;
using DFHack::struct_field_info;
using DFHack::struct_field_info_extra;
using DFHack::bitfield_item_info;