ruby: add d-float support

develop
jj 2012-12-04 17:18:09 +01:00
parent 3953112eb9
commit 0b80dff09d
3 changed files with 32 additions and 0 deletions

@ -849,6 +849,9 @@ sub render_item_number {
} elsif ($subtype eq 's-float') {
push @lines_rb, 'float';
return;
} elsif ($subtype eq 'd-float') {
push @lines_rb, 'double';
return;
} else {
print "no render number $subtype\n";
return;

@ -35,6 +35,9 @@ module DFHack
def float
Float.new
end
def double
Double.new
end
def bit(shift, enum=nil)
BitField.new(shift, 1, enum)
end
@ -237,6 +240,19 @@ module DFHack
_set(0.0)
end
end
class Double < MemStruct
def _get
DFHack.memory_read_double(@_memaddr)
end
def _set(v)
DFHack.memory_write_double(@_memaddr, v)
end
def _cpp_init
_set(0.0)
end
end
class BitField < MemStruct
attr_accessor :_shift, :_len, :_enum
def initialize(shift, len, enum=nil)

@ -578,6 +578,11 @@ static VALUE rb_dfmemory_read_float(VALUE self, VALUE addr)
return rb_float_new(*(float*)rb_num2ulong(addr));
}
static VALUE rb_dfmemory_read_double(VALUE self, VALUE addr)
{
return rb_float_new(*(double*)rb_num2ulong(addr));
}
// memory writing (buffer)
static VALUE rb_dfmemory_write(VALUE self, VALUE addr, VALUE raw)
@ -613,6 +618,12 @@ static VALUE rb_dfmemory_write_float(VALUE self, VALUE addr, VALUE val)
return Qtrue;
}
static VALUE rb_dfmemory_write_double(VALUE self, VALUE addr, VALUE val)
{
*(double*)rb_num2ulong(addr) = rb_num2dbl(val);
return Qtrue;
}
// return memory permissions at address (eg "rx", nil if unmapped)
static VALUE rb_dfmemory_check(VALUE self, VALUE addr)
{
@ -968,12 +979,14 @@ static void ruby_bind_dfhack(void) {
rb_define_singleton_method(rb_cDFHack, "memory_read_int16", RUBY_METHOD_FUNC(rb_dfmemory_read_int16), 1);
rb_define_singleton_method(rb_cDFHack, "memory_read_int32", RUBY_METHOD_FUNC(rb_dfmemory_read_int32), 1);
rb_define_singleton_method(rb_cDFHack, "memory_read_float", RUBY_METHOD_FUNC(rb_dfmemory_read_float), 1);
rb_define_singleton_method(rb_cDFHack, "memory_read_double", RUBY_METHOD_FUNC(rb_dfmemory_read_double), 1);
rb_define_singleton_method(rb_cDFHack, "memory_write", RUBY_METHOD_FUNC(rb_dfmemory_write), 2);
rb_define_singleton_method(rb_cDFHack, "memory_write_int8", RUBY_METHOD_FUNC(rb_dfmemory_write_int8), 2);
rb_define_singleton_method(rb_cDFHack, "memory_write_int16", RUBY_METHOD_FUNC(rb_dfmemory_write_int16), 2);
rb_define_singleton_method(rb_cDFHack, "memory_write_int32", RUBY_METHOD_FUNC(rb_dfmemory_write_int32), 2);
rb_define_singleton_method(rb_cDFHack, "memory_write_float", RUBY_METHOD_FUNC(rb_dfmemory_write_float), 2);
rb_define_singleton_method(rb_cDFHack, "memory_write_double", RUBY_METHOD_FUNC(rb_dfmemory_write_double), 2);
rb_define_singleton_method(rb_cDFHack, "memory_check", RUBY_METHOD_FUNC(rb_dfmemory_check), 1);
rb_define_singleton_method(rb_cDFHack, "memory_patch", RUBY_METHOD_FUNC(rb_dfmemory_patch), 2);