Class: FFIGen::Struct
- Inherits:
-
Object
- Object
- FFIGen::Struct
- Defined in:
- lib/ffi_gen.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
-
#initialize(generator, name, comment) ⇒ Struct
constructor
A new instance of Struct.
- #reference ⇒ Object
- #ruby_name ⇒ Object
- #type_name(short) ⇒ Object
- #write(writer) ⇒ Object
Constructor Details
#initialize(generator, name, comment) ⇒ Struct
Returns a new instance of Struct.
102 103 104 105 106 107 |
# File 'lib/ffi_gen.rb', line 102 def initialize(generator, name, comment) @generator = generator @name = name @comment = comment @fields = [] end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
100 101 102 |
# File 'lib/ffi_gen.rb', line 100 def fields @fields end |
Instance Method Details
#reference ⇒ Object
142 143 144 |
# File 'lib/ffi_gen.rb', line 142 def reference "#{ruby_name}.by_value" end |
#ruby_name ⇒ Object
134 135 136 |
# File 'lib/ffi_gen.rb', line 134 def ruby_name @ruby_name ||= @generator.to_ruby_camelcase @name end |
#type_name(short) ⇒ Object
138 139 140 |
# File 'lib/ffi_gen.rb', line 138 def type_name(short) ruby_name end |
#write(writer) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ffi_gen.rb', line 109 def write(writer) @fields.each do |field| field[:symbol] = ":#{@generator.to_ruby_lowercase field[:name]}" end writer.comment do writer.write_description @comment unless @fields.empty? writer.puts "", "= Fields:" @fields.each do |field| writer.puts "#{field[:symbol]} ::" writer.write_description field[:comment], false, " (#{@generator.to_type_name field[:type]}) ", " " end end end writer.puts "class #{ruby_name} < FFI::Struct" writer.indent do writer.write_array @fields, ",", "layout ", " " do |field| "#{field[:symbol]}, #{@generator.to_ffi_type field[:type]}" end end writer.puts "end", "" end |