ruby: tweak enums, pointerary

develop
jj 2012-05-06 22:42:06 +02:00
parent bfb26f1c1f
commit 7ee4c584b9
2 changed files with 14 additions and 3 deletions

@ -65,6 +65,7 @@ sub render_enum_fields {
push @lines_rb, "$idxname = Hash.new";
my %attr_type;
my %attr_list;
for my $attr ($type->findnodes('child::enum-attr')) {
my $rbattr = rb_ucase($attr->getAttribute('name'));
my $typeattr = $attr->getAttribute('type-name');
@ -80,7 +81,10 @@ sub render_enum_fields {
}
my $def = $attr->getAttribute('default-value');
if ($def) {
if ($attr->getAttribute('is-list')) {
push @lines_rb, "$rbattr = Hash.new { |h, k| h[k] = [] }";
$attr_list{$rbattr} = 1;
} elsif ($def) {
$def = ":$def" if ($attr_type{$rbattr} eq 'symbol');
$def =~ s/'/\\'/g if ($attr_type{$rbattr} eq 'quote');
$def = "'$def'" if ($attr_type{$rbattr} eq 'quote');
@ -101,10 +105,11 @@ sub render_enum_fields {
my $ian = $iattr->getAttribute('name');
my $iav = $iattr->getAttribute('value');
my $rbattr = rb_ucase($ian);
my $op = ($attr_list{$rbattr} ? '<<' : '=');
$iav = ":$iav" if ($attr_type{$rbattr} eq 'symbol');
$iav =~ s/'/\\'/g if ($attr_type{$rbattr} eq 'quote');
$iav = "'$iav'" if ($attr_type{$rbattr} eq 'quote');
$lines_rb[$#lines_rb] .= " ; ${rbattr}[$value] = $iav";
$lines_rb[$#lines_rb] .= " ; ${rbattr}[:$rbelemname] $op $iav";
}
}
}

@ -294,6 +294,12 @@ class PointerAry < MemStruct
(DFHack.memory_read_int32(@_memaddr) & 0xffffffff) + delta
end
def _get
addr = _getp
return if addr == 0
self
end
def [](i)
addr = _getp(i)
return if addr == 0
@ -305,7 +311,7 @@ class PointerAry < MemStruct
@_tg._at(addr)._set(v)
end
def inspect ; "#<PointerAry #{'0x%X' % _getp}>" ; end
def inspect ; ptr = _getp ; (ptr == 0) ? 'NULL' : "#<PointerAry #{'0x%X' % ptr}>" ; end
end
module IndexEnum
def indexenum(idx)