ruby: use enums in single-bit values too

develop
jj 2012-08-03 16:53:54 +02:00
parent 160487f7eb
commit f400591080
2 changed files with 8 additions and 8 deletions

@ -175,10 +175,10 @@ sub render_bitfield_fields {
if ($name)
{
if ($count == 1) {
push @lines_rb, "field(:$name, 0) { bit $shift }";
} elsif ($enum) {
if ($enum) {
push @lines_rb, "field(:$name, 0) { bits $shift, $count, $enum }";
} elsif ($count == 1) {
push @lines_rb, "field(:$name, 0) { bit $shift }";
} else {
push @lines_rb, "field(:$name, 0) { bits $shift, $count }";
}

@ -34,8 +34,8 @@ module DFHack
def float
Float.new
end
def bit(shift)
BitField.new(shift, 1)
def bit(shift, enum=nil)
BitField.new(shift, 1, enum)
end
def bits(shift, len, enum=nil)
BitField.new(shift, len, enum)
@ -147,7 +147,7 @@ module DFHack
out << '>'
end
def inspect_field(n, o, s)
if s.kind_of?(BitField) and s._len == 1
if s.kind_of?(BitField) and s._len == 1 and not s._enum
send(n) ? n.to_s : ''
elsif s.kind_of?(Pointer)
"#{n}=#{s._at(@_memaddr+o).inspect}"
@ -242,7 +242,7 @@ module DFHack
def _get
v = DFHack.memory_read_int32(@_memaddr) >> @_shift
if @_len == 1
if @_len == 1 and not @_enum
((v & 1) == 0) ? false : true
else
v &= _mask
@ -252,7 +252,7 @@ module DFHack
end
def _set(v)
if @_len == 1
if @_len == 1 and (not @_enum or v == false or v == true)
# allow 'bit = 0'
v = (v && v != 0 ? 1 : 0)
end