diff --git a/plugins/ruby/codegen.pl b/plugins/ruby/codegen.pl index 81ca15137..4f0d04ebe 100755 --- a/plugins/ruby/codegen.pl +++ b/plugins/ruby/codegen.pl @@ -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"; } } } diff --git a/plugins/ruby/ruby-memstruct.rb b/plugins/ruby/ruby-memstruct.rb index cf8a54d9e..4393cc76c 100644 --- a/plugins/ruby/ruby-memstruct.rb +++ b/plugins/ruby/ruby-memstruct.rb @@ -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 ; "#" ; end + def inspect ; ptr = _getp ; (ptr == 0) ? 'NULL' : "#" ; end end module IndexEnum def indexenum(idx)