Class C
In: lib/inline.rb
Parent: Object

Inline::C is the default builder used and the only one provided by Inline. It can be used as a template to write builders for other languages. It understands type-conversions for the basic types and can be extended as needed using add_type_converter, alias_type_converter and remove_type_converter.

Methods

Included Modules

ZenTestMapping

Constants

MAGIC_ARITY_THRESHOLD = 15
MAGIC_ARITY = -1
TYPE_MAP = { 'char' => [ 'NUM2CHR', 'CHR2FIX' ], 'char *' => [ 'StringValuePtr', 'rb_str_new2' ], 'double' => [ 'NUM2DBL', 'rb_float_new' ], 'int' => [ "FI\X2INT", 'INT2FIX' ], 'unsigned int' => [ 'NUM2UINT', 'UINT2NUM' ], 'unsigned' => [ 'NUM2UINT', 'UINT2NUM' ], 'long' => [ 'NUM2LONG', 'LONG2NUM' ], 'unsigned long' => [ 'NUM2ULONG', 'ULONG2NUM' ], 'long long' => [ 'NUM2LL', 'LL2NUM' ], 'unsigned long long' => [ 'NUM2ULL', 'ULL2NUM' ], 'off_t' => [ 'NUM2OFFT', 'OFFT2NUM' ], 'VALUE' => [ '', '' ], # Can't do these converters because they conflict with the above: # ID2SYM(x), SYM2ID(x), F\IX2UINT(x) }   Default C to ruby and ruby to C type map

Attributes

flags  [RW] 
init_extra  [RW] 
libs  [RW] 
mod  [W] 
mod  [R] 
rb_file  [R] 
sig  [RW] 
src  [RW] 
struct_name  [RW]  Sets the name of the C struct for generating accessors. Used with accessor, reader, writer.

Public Class methods

Public Instance methods

Adds a reader and writer for a C struct member wrapped via Data_Wrap_Struct. method is the ruby name to give the accessor, type is the C type. Unless the C member name is overridden with member, the method name is used as the struct member.

  builder.struct_name = 'MyStruct'
  builder.accessor :title,        'char *'
  builder.accessor :stream_index, 'int',   :index

The latter accesses MyStruct->index via the stream_index method.

Adds compiler options to the compiler command line. No preprocessing is done, so you must have all your dashes and everything.

Adds linker flags to the link command line. No preprocessing is done, so you must have all your dashes and everything.

Create a static variable and initialize it to a value.

Adds custom content to the end of the init function.

Registers C type-casts +r2c+ and +c2r+ for type.

Registers C type alias_type as an alias of existing_type

Builds the source file, if needed, and attempts to compile it.

Adds a C function to the source, including performing automatic type conversion to arguments and the return value. The Ruby method name can be overridden by providing method_name. Unknown type conversions can be extended by using add_type_converter.

Converts C type type to a ruby type

Adds a raw C function to the source. This version does not perform any type conversion and must conform to the ruby/C coding conventions. The Ruby method name can be overridden by providing method_name.

Same as c_raw, but adds a class function.

Same as c, but adds a class function.

Returns extra compilation flags for windoze platforms. Ugh.

Builds a complete C extension suitable for writing to a file and compiling.

Adds an include to the top of the file. Don‘t forget to use quotes or angle brackets.

Specifies that the the ruby.h header should be included after custom header(s) instead of before them.

Loads the generated code back into ruby

Attempts to load pre-generated code returning true if it succeeds.

Maps a C constant to ruby. names_and_types is a hash that maps the name of the constant to its C type.

  builder.map_c_const :C_NAME => :int

If you wish to give the constant a different ruby name:

  builder.map_c_const :C_NAME => [:int, :RUBY_NAME]

Maps a ruby constant to C (with the same name)

Adds any amount of text/code to the source

Adds a reader for a C struct member wrapped via Data_Wrap_Struct. method is the ruby name to give the reader, type is the C type. Unless the C member name is overridden with member, the method name is used as the struct member. See accessor for an example.

Unregisters C type-casts for type.

Converts ruby type type to a C type

Adds a writer for a C struct member wrapped via Data_Get_Struct. method is the ruby name to give the writer, type is the C type. Unless the C member name is overridden with member, the method name is used as the struct member. See accessor for an example.

[Validate]