ruby: guard against undefined globals, fix inspect for inherited classes

develop
jj 2012-04-24 19:07:54 +02:00
parent eca17fff53
commit 7a71204b82
2 changed files with 16 additions and 5 deletions

@ -199,12 +199,17 @@ sub render_global_objects {
for my $obj (@objects) {
my $oname = $obj->getAttribute('name');
my $addr = "DFHack.get_global_address('$oname')";
push @lines_rb, "field(:$oname, $addr) {";
my $item = $obj->findnodes('child::ld:item')->[0];
push @lines_rb, "addr = $addr";
push @lines_rb, "if addr != 0";
indent_rb {
render_item($item, 'df::global');
push @lines_rb, "field(:$oname, addr) {";
my $item = $obj->findnodes('child::ld:item')->[0];
indent_rb {
render_item($item, 'df::global');
};
push @lines_rb, "}";
};
push @lines_rb, "}";
push @lines_rb, "end";
push @global_objects, $oname;
}

@ -95,7 +95,13 @@ class Compound < MemStruct
cn = self.class.name.sub(/^DFHack::/, '')
cn << ' @' << ('0x%X' % _memaddr) if cn != ''
out = "#<#{cn}"
_fields.each { |n, o, s|
fields = _fields
cls = self.class.superclass
while cls.respond_to?(:_fields)
fields += cls._fields.to_a
cls = cls.superclass
end
fields.each { |n, o, s|
out << ' ' if out.length != 0 and out[-1, 1] != ' '
if out.length > 1024
out << '...'