Class: C

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

accessor add_compile_flags add_link_flags add_static add_to_init add_type_converter alias_type_converter build c c2ruby c_raw c_raw_singleton c_singleton crap_for_windoze generate generate_ext include include_ruby_last load load_cache map_c_const map_ruby_const module_name new parse_signature prefix reader remove_type_converter ruby2c so_name strip_comments writer

### 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

new(mod)

### Public Instance methods

accessor(method, type, member = method)

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.

add_compile_flags(*flags)

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

add_link_flags(*flags)

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

add_static(name, init, type = "VALUE")

Create a static variable and initialize it to a value.

add_to_init(*src)

Adds custom content to the end of the init function.

add_type_converter(type, r2c, c2r)

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

alias_type_converter(existing_type, alias_type)

Registers C type `alias_type` as an alias of `existing_type`

build()

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

c(src, options = {})

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`.

c2ruby(type)

Converts C type `type` to a ruby type

c_raw(src, options = {})

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.

c_raw_singleton(src, options = {})

Same as `c_raw`, but adds a class function.

c_singleton(src, options = {})

Same as `c`, but adds a class function.

crap_for_windoze()

Returns extra compilation flags for windoze platforms. Ugh.

generate(src, options={})
generate_ext()

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

include(header)

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

include_ruby_last()

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

load()

Loads the generated code back into ruby

load_cache()

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

map_c_const(names_and_types)

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]

map_ruby_const(*names)

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

module_name()
parse_signature(src, raw=false)
prefix(code)

Adds any amount of text/code to the source

reader(method, type, member = method)

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.

remove_type_converter(type)

Unregisters C type-casts for `type`.

ruby2c(type)

Converts ruby type `type` to a C type

so_name()
strip_comments(src)
writer(method, type, member = method)

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]