Class | FFI::ConstGenerator |
In: |
lib/ffi/tools/const_generator.rb
|
Parent: | Object |
ConstGenerator turns C constants into ruby values.
@example a simple example for stdio
cg = FFI::ConstGenerator.new('stdio') do |gen| gen.const(:SEEK_SET) gen.const('SEEK_CUR') gen.const('seek_end') # this constant does not exist end # #calculate called automatically at the end of the block cg['SEEK_SET'] # => 0 cg['SEEK_CUR'] # => 1 cg['seek_end'] # => nil cg.to_ruby # => "SEEK_SET = 0\nSEEK_CUR = 1\n# seek_end not available"
constants | [R] |
Creates a new constant generator that uses prefix as a name, and an options hash.
The only option is +:required+, which if set to true raises an error if a constant you have requested was not found.
@param [to_s] prefix @param [Hash] options @return @option options [Boolean] :required @overload initialize(prefix, options) @overload initialize(prefix, options) { |gen| … }
@yieldparam [ConstGenerator] gen new generator is passed to the block When passed a block, {#calculate} is automatically called at the end of the block, otherwise you must call it yourself.
@param [String] name @return constant value (converted if a converter was defined). Access a constant by name.
Request the value for C constant name.
@param [to_s] name C constant name @param [String] format a printf format string to print the value out @param [String] cast a C cast for the value @param ruby_name alternate ruby name for {to_ruby}
@overload const(name, format=nil, cast=’’, ruby_name=nil, converter=nil)
+converter+ is a Method or a Proc. @param [#call] converter convert the value from a string to the appropriate type for {#to_ruby}.
@overload const(name, format=nil, cast=’’, ruby_name=nil) { |value| … }
Use a converter block. This block convert the value from a string to the appropriate type for {#to_ruby}. @yieldparam value constant value