Ruby implementation of df-other-vectors-type

develop
Ben Lubar 2020-04-28 14:26:33 -05:00
parent 6c20fe4c80
commit 28c34217d8
No known key found for this signature in database
GPG Key ID: 92939677AB59EDA4
2 changed files with 24 additions and 0 deletions

@ -240,6 +240,12 @@ sub render_global_class {
}
my $rbparent = ($parent ? rb_ucase($parent) : 'MemHack::Compound');
my $ienum;
if (($type->getAttribute('ld:subtype') or '') eq 'df-other-vectors-type')
{
$rbparent = 'MemHack::OtherVectors';
$ienum = rb_ucase($type->getAttribute('index-enum'));
}
push @lines_rb, "class $rbname < $rbparent";
indent_rb {
my $sz = sizeof($type);
@ -249,6 +255,8 @@ sub render_global_class {
push @lines_rb, "rtti_classname :$rtti_name\n" if $rtti_name;
push @lines_rb, "ienum $ienum\n" if $ienum;
render_struct_fields($type);
my $vms = $type->findnodes('child::virtual-methods')->[0];

@ -205,6 +205,22 @@ module DFHack
end
end
class OtherVectors < Compound
class << self
attr_accessor :_enum
def ienum(enum)
@_enum = enum
end
end
def [](i)
self.send(self.class._enum.sym(i))
end
def []=(i, v)
self.send((self.class._enum.sym(i).to_s + "=").to_sym, v)
end
end
class Enum
# number -> symbol
def self.enum