diff options
| author | jj | 2012-09-19 14:25:14 +0200 |
|---|---|---|
| committer | jj | 2012-09-19 14:25:14 +0200 |
| commit | 45c057b3d2e5809941fc618624b955ffa46b0b87 (patch) | |
| tree | e31ea3e5894c72bdcd1931d79c7d66c7928a64b7 /plugins/ruby | |
| parent | b470abed904f31aa3c886ffc47e84d0f14322a58 (diff) | |
| download | dfhack-45c057b3d2e5809941fc618624b955ffa46b0b87.tar.gz dfhack-45c057b3d2e5809941fc618624b955ffa46b0b87.tar.bz2 dfhack-45c057b3d2e5809941fc618624b955ffa46b0b87.tar.xz | |
ruby: handle ptr-strings in df-structures
Diffstat (limited to 'plugins/ruby')
| -rwxr-xr-x | plugins/ruby/codegen.pl | 2 | ||||
| -rw-r--r-- | plugins/ruby/ruby-autogen-defs.rb | 13 |
2 files changed, 12 insertions, 3 deletions
diff --git a/plugins/ruby/codegen.pl b/plugins/ruby/codegen.pl index 8cd06b36..a615ab96 100755 --- a/plugins/ruby/codegen.pl +++ b/plugins/ruby/codegen.pl @@ -965,7 +965,7 @@ sub render_item_bytes { my $subtype = $item->getAttribute('ld:subtype'); if ($subtype eq 'padding') { } elsif ($subtype eq 'static-string') { - my $size = $item->getAttribute('size'); + my $size = $item->getAttribute('size') || -1; push @lines_rb, "static_string($size)"; } else { print "no render bytes $subtype\n"; diff --git a/plugins/ruby/ruby-autogen-defs.rb b/plugins/ruby/ruby-autogen-defs.rb index 4614d178..64c08fac 100644 --- a/plugins/ruby/ruby-autogen-defs.rb +++ b/plugins/ruby/ruby-autogen-defs.rb @@ -423,11 +423,20 @@ module DFHack def initialize(length) @_length = length end + def length + if @_length == -1 + maxlen = 4096 - (@_memaddr & 0xfff) + maxlen += 4096 until len = DFHack.memory_read(@_memaddr, maxlen).index(?\0) + len + else + @_length + end + end def _get - DFHack.memory_read(@_memaddr, @_length) + DFHack.memory_read(@_memaddr, length) end def _set(v) - DFHack.memory_write(@_memaddr, v[0, @_length]) + DFHack.memory_write(@_memaddr, v[0, length]) end end |
