|
|
@ -4,6 +4,7 @@ class MemStruct
|
|
|
|
attr_accessor :_memaddr
|
|
|
|
attr_accessor :_memaddr
|
|
|
|
def _at(addr) ; d = dup ; d._memaddr = addr ; d ; end
|
|
|
|
def _at(addr) ; d = dup ; d._memaddr = addr ; d ; end
|
|
|
|
def _get ; self ; end
|
|
|
|
def _get ; self ; end
|
|
|
|
|
|
|
|
def _cpp_init ; end
|
|
|
|
def inspect ; _get.inspect ; end
|
|
|
|
def inspect ; _get.inspect ; end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -25,8 +26,8 @@ class Compound < MemStruct
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def number(bits, signed)
|
|
|
|
def number(bits, signed, initvalue=nil)
|
|
|
|
Number.new(bits, signed)
|
|
|
|
Number.new(bits, signed, initvalue)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def float
|
|
|
|
def float
|
|
|
|
Float.new
|
|
|
|
Float.new
|
|
|
@ -101,22 +102,13 @@ class Compound < MemStruct
|
|
|
|
DFHack.memory_write_int32(ptr, vt)
|
|
|
|
DFHack.memory_write_int32(ptr, vt)
|
|
|
|
# TODO call constructor
|
|
|
|
# TODO call constructor
|
|
|
|
end
|
|
|
|
end
|
|
|
|
new._at(ptr)._cpp_init
|
|
|
|
o = new._at(ptr)
|
|
|
|
|
|
|
|
o._cpp_init
|
|
|
|
|
|
|
|
o
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def _cpp_init
|
|
|
|
def _cpp_init
|
|
|
|
_fields.each { |n, o, s|
|
|
|
|
_fields_ancestors.each { |n, o, s| s._at(@_memaddr+o)._cpp_init }
|
|
|
|
case s
|
|
|
|
|
|
|
|
when StlString
|
|
|
|
|
|
|
|
DFHack.memory_stlstring_init(@_memaddr+o)
|
|
|
|
|
|
|
|
when StlVector32
|
|
|
|
|
|
|
|
# englobes all vectors
|
|
|
|
|
|
|
|
DFHack.memory_vector_init(@_memaddr+o)
|
|
|
|
|
|
|
|
when Compound
|
|
|
|
|
|
|
|
send(n)._cpp_init
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def _set(h) ; h.each { |k, v| send("_#{k}=", v) } ; end
|
|
|
|
def _set(h) ; h.each { |k, v| send("_#{k}=", v) } ; end
|
|
|
|
def _fields ; self.class._fields.to_a ; end
|
|
|
|
def _fields ; self.class._fields.to_a ; end
|
|
|
@ -152,10 +144,11 @@ class Compound < MemStruct
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
class Number < MemStruct
|
|
|
|
class Number < MemStruct
|
|
|
|
attr_accessor :_bits, :_signed
|
|
|
|
attr_accessor :_bits, :_signed, :_initvalue
|
|
|
|
def initialize(bits, signed)
|
|
|
|
def initialize(bits, signed, initvalue)
|
|
|
|
@_bits = bits
|
|
|
|
@_bits = bits
|
|
|
|
@_signed = signed
|
|
|
|
@_signed = signed
|
|
|
|
|
|
|
|
@_initvalue = initvalue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def _get
|
|
|
|
def _get
|
|
|
@ -177,6 +170,10 @@ class Number < MemStruct
|
|
|
|
when 64; DFHack.memory_write_int32(@_memaddr, v & 0xffffffff) ; DFHack.memory_write_int32(@memaddr+4, v>>32)
|
|
|
|
when 64; DFHack.memory_write_int32(@_memaddr, v & 0xffffffff) ; DFHack.memory_write_int32(@memaddr+4, v>>32)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _cpp_init
|
|
|
|
|
|
|
|
_set(@_initvalue) if @_initvalue
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class Float < MemStruct
|
|
|
|
class Float < MemStruct
|
|
|
|
# _get/_set defined in ruby.cpp
|
|
|
|
# _get/_set defined in ruby.cpp
|
|
|
@ -187,6 +184,10 @@ class Float < MemStruct
|
|
|
|
def _set(v)
|
|
|
|
def _set(v)
|
|
|
|
DFHack.memory_write_float(@_memaddr, v)
|
|
|
|
DFHack.memory_write_float(@_memaddr, v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _cpp_init
|
|
|
|
|
|
|
|
_set(0.0)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class BitField < MemStruct
|
|
|
|
class BitField < MemStruct
|
|
|
|
attr_accessor :_shift, :_len
|
|
|
|
attr_accessor :_shift, :_len
|
|
|
@ -308,6 +309,9 @@ class StaticArray < MemStruct
|
|
|
|
def _set(a)
|
|
|
|
def _set(a)
|
|
|
|
a.each_with_index { |v, i| self[i] = v }
|
|
|
|
a.each_with_index { |v, i| self[i] = v }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def _cpp_init
|
|
|
|
|
|
|
|
_length.times { |i| _tgat(i)._cpp_init }
|
|
|
|
|
|
|
|
end
|
|
|
|
alias length _length
|
|
|
|
alias length _length
|
|
|
|
alias size _length
|
|
|
|
alias size _length
|
|
|
|
def _tgat(i)
|
|
|
|
def _tgat(i)
|
|
|
@ -334,6 +338,7 @@ class StaticArray < MemStruct
|
|
|
|
to_a.inspect
|
|
|
|
to_a.inspect
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def flatten ; map { |e| e.respond_to?(:flatten) ? e.flatten : e }.flatten ; end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class StaticString < MemStruct
|
|
|
|
class StaticString < MemStruct
|
|
|
|
attr_accessor :_length
|
|
|
|
attr_accessor :_length
|
|
|
@ -373,6 +378,10 @@ class StlVector32 < MemStruct
|
|
|
|
v.each_with_index { |e, i| self[i] = e } # patch entries
|
|
|
|
v.each_with_index { |e, i| self[i] = e } # patch entries
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _cpp_init
|
|
|
|
|
|
|
|
DFHack.memory_vector_init(@_memaddr)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def clear
|
|
|
|
def clear
|
|
|
|
delete_at(length-1) while length > 0
|
|
|
|
delete_at(length-1) while length > 0
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -475,6 +484,10 @@ class StlString < MemStruct
|
|
|
|
def _set(v)
|
|
|
|
def _set(v)
|
|
|
|
DFHack.memory_write_stlstring(@_memaddr, v)
|
|
|
|
DFHack.memory_write_stlstring(@_memaddr, v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _cpp_init
|
|
|
|
|
|
|
|
DFHack.memory_stlstring_init(@_memaddr)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class StlDeque < MemStruct
|
|
|
|
class StlDeque < MemStruct
|
|
|
|
attr_accessor :_tglen, :_tg
|
|
|
|
attr_accessor :_tglen, :_tg
|
|
|
@ -496,6 +509,7 @@ class DfFlagarray < MemStruct
|
|
|
|
def length
|
|
|
|
def length
|
|
|
|
DFHack.memory_bitarray_length(@_memaddr)
|
|
|
|
DFHack.memory_bitarray_length(@_memaddr)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# TODO _cpp_init
|
|
|
|
def size ; length ; end
|
|
|
|
def size ; length ; end
|
|
|
|
def resize(len)
|
|
|
|
def resize(len)
|
|
|
|
DFHack.memory_bitarray_resize(@_memaddr, len)
|
|
|
|
DFHack.memory_bitarray_resize(@_memaddr, len)
|
|
|
@ -538,6 +552,7 @@ class DfArray < Compound
|
|
|
|
|
|
|
|
|
|
|
|
def length ; _length ; end
|
|
|
|
def length ; _length ; end
|
|
|
|
def size ; _length ; end
|
|
|
|
def size ; _length ; end
|
|
|
|
|
|
|
|
# TODO _cpp_init
|
|
|
|
def _tgat(i)
|
|
|
|
def _tgat(i)
|
|
|
|
@_tg._at(_ptr + i*@_tglen) if i >= 0 and i < _length
|
|
|
|
@_tg._at(_ptr + i*@_tglen) if i >= 0 and i < _length
|
|
|
|
end
|
|
|
|
end
|
|
|
|