Class: FFIGen::Define

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi_gen.rb,
lib/ffi_gen/java_output.rb,
lib/ffi_gen/ruby_output.rb

Instance Method Summary collapse

Constructor Details

#initialize(generator, name, parameters, value) ⇒ Define

Returns a new instance of Define.



127
128
129
130
131
132
# File 'lib/ffi_gen.rb', line 127

def initialize(generator, name, parameters, value)
  @generator = generator
  @name = name
  @parameters = parameters
  @value = value
end

Instance Method Details

#write_java(writer) ⇒ Object



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/ffi_gen/java_output.rb', line 258

def write_java(writer)
  parts = @value.map { |v|
    if v.is_a? Array
      case v[0]
      when :method then v[1].to_java_downcase
      when :constant then v[1].to_java_constant
      else raise ArgumentError
      end
    else
      v
    end
  }
  if @parameters
    # not implemented
  else
    writer.puts "public static int #{@name.to_java_constant} = #{parts.join};", ""
  end
end

#write_ruby(writer) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/ffi_gen/ruby_output.rb', line 189

def write_ruby(writer)
  parts = @value.map { |v|
    if v.is_a? Array
      case v[0]
      when :method then v[1].to_ruby_downcase
      when :constant then v[1].to_ruby_constant
      else raise ArgumentError
      end
    else
      v
    end
  }
  if @parameters
    writer.puts "def #{@name.to_ruby_downcase}(#{@parameters.join(", ")})"
    writer.indent do
      writer.puts parts.join
    end
    writer.puts "end", ""
  else
    writer.puts "#{@name.to_ruby_constant} = #{parts.join}", ""
  end
end