|
|
@ -152,28 +152,29 @@ class Pointer < MemStruct
|
|
|
|
@_tg = tg
|
|
|
|
@_tg = tg
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def _getp
|
|
|
|
def _getp(i=0)
|
|
|
|
DFHack.memory_read_int32(@_memaddr) & 0xffffffff
|
|
|
|
delta = (i != 0 ? i*@_tglen : 0)
|
|
|
|
|
|
|
|
(DFHack.memory_read_int32(@_memaddr) & 0xffffffff) + delta
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def _setp(v)
|
|
|
|
def _setp(v)
|
|
|
|
DFHack.memory_write_int32(@_memaddr, v)
|
|
|
|
DFHack.memory_write_int32(@_memaddr, v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def _get ; self ; end
|
|
|
|
|
|
|
|
|
|
|
|
# _getp/_setp defined in ruby.cpp, access the pointer value
|
|
|
|
def [](i)
|
|
|
|
def _get
|
|
|
|
addr = _getp(i)
|
|
|
|
addr = _getp
|
|
|
|
return if addr == 0
|
|
|
|
return if addr == 0 # XXX are there pointers with -1 as 'empty' value ?
|
|
|
|
|
|
|
|
@_tg._at(addr)._get
|
|
|
|
@_tg._at(addr)._get
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def _set(v)
|
|
|
|
def []=(i, v)
|
|
|
|
addr = _getp
|
|
|
|
addr = _getp(i)
|
|
|
|
raise 'null pointer' if addr == 0 # TODO malloc ?
|
|
|
|
raise 'null pointer' if addr == 0
|
|
|
|
@_tg._at(addr)._set(v)
|
|
|
|
@_tg._at(addr)._set(v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# the pointer is invisible, forward all methods to the pointed object
|
|
|
|
# the pointer is invisible, forward all methods to the pointed object
|
|
|
|
def method_missing(*a)
|
|
|
|
def method_missing(*a)
|
|
|
|
_get.send(*a)
|
|
|
|
self[0].send(*a)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class StaticArray < MemStruct
|
|
|
|
class StaticArray < MemStruct
|
|
|
@ -193,11 +194,11 @@ class StaticArray < MemStruct
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def [](i)
|
|
|
|
def [](i)
|
|
|
|
i += @_length if i < 0
|
|
|
|
i += @_length if i < 0
|
|
|
|
tgat(i)._get
|
|
|
|
_tgat(i)._get
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def []=(i, v)
|
|
|
|
def []=(i, v)
|
|
|
|
i += @_length if i < 0
|
|
|
|
i += @_length if i < 0
|
|
|
|
tgat(i)._set(v)
|
|
|
|
_tgat(i)._set(v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
include Enumerable
|
|
|
|
include Enumerable
|
|
|
|