summaryrefslogtreecommitdiff
path: root/plugins/ruby
diff options
context:
space:
mode:
authorjj2012-08-03 16:53:54 +0200
committerjj2012-08-03 16:53:54 +0200
commitf400591080b29add7b64d196b4bf3911c2803ded (patch)
tree95c748ac2c38e16f8ecbdd6448ac0ab1861288f6 /plugins/ruby
parent160487f7eb7fcc019644102f595a73e334f463d7 (diff)
downloaddfhack-f400591080b29add7b64d196b4bf3911c2803ded.tar.gz
dfhack-f400591080b29add7b64d196b4bf3911c2803ded.tar.bz2
dfhack-f400591080b29add7b64d196b4bf3911c2803ded.tar.xz
ruby: use enums in single-bit values too
Diffstat (limited to 'plugins/ruby')
-rwxr-xr-xplugins/ruby/codegen.pl6
-rw-r--r--plugins/ruby/ruby-autogen-defs.rb10
2 files changed, 8 insertions, 8 deletions
diff --git a/plugins/ruby/codegen.pl b/plugins/ruby/codegen.pl
index cbe7c932..593216d7 100755
--- a/plugins/ruby/codegen.pl
+++ b/plugins/ruby/codegen.pl
@@ -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 }";
}
diff --git a/plugins/ruby/ruby-autogen-defs.rb b/plugins/ruby/ruby-autogen-defs.rb
index a1cba416..2e4948ac 100644
--- a/plugins/ruby/ruby-autogen-defs.rb
+++ b/plugins/ruby/ruby-autogen-defs.rb
@@ -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