[ANN] CGenerator 0.11

Cgenerator 0.11

···

===============

What is it?

Framework for dynamically generating C extensions from Ruby. Supports
automatic management of C structs as ruby objects that:

  • have accessible, type-safe attributes
  • can be serialized via Marshal and YAML
  • are GC-aware
  • are fully inheritable and extensible with new attributes.

Who needs it?

If you’re starting a C extension from scratch, or if you need to
dynamically generate and load C code on the fly, you may be interested.
For wrapping an existing library, you should consider SWIG as well. SWIG
has the advantage of being able to parse headers and generate something
as a starting point. CGenerator has the advantage of automatically
handling serialization and memory management, but it can handle only a
limited (but extensible) range of C data types.

What’s new?

The most important change is that all shadow classes can now load and
dump YAML strings (and they do so without generating any more C
code–the dump/load code for attributes is generic enough to work with
YAML as well as Marshal).

An example:


require 'cgen/cshadow’
require ‘yaml’

CShadow.allow_yaml

class YamlExample
include CShadow
shadow_attr_accessor :x => "int x"
shadow_attr_accessor :z => “double z”

attr_accessor :a, :b

def initialize(x, z, a, b)
self.x = x
self.z = z
@a = a
@b = b
end
end

Dir.chdir(’/tmp’) do
YamlExample.commit
end

obj = YamlExample.new(1,2.6, :AAA, “BBB”)
y obj

obj2 = YAML.load(YAML.dump(obj))
y obj2

END

Output:

— !ruby/cshadow:YamlExample
x: 1
z: 2.6
b: BBB
a: !ruby/sym AAA
— !ruby/cshadow:YamlExample
x: 1
z: 2.6
b: BBB
a: !ruby/sym AAA

Joel VanderWerf wrote:

Cgenerator 0.11

Where is it?

···

============

http://raa.ruby-lang.org/list.rhtml?name=cgenerator

Oops.