From: Joel VanderWerf Date: 2007-09-23T04:08:36+09:00 Subject: Re: [ANN] CplusRuby - Gluing C and Ruby Michael Neumann wrote: > Hi all, > > I am proud to announce my latest project called CplusRuby. > Below I pasted it's README for further explanation. > Alternatively read the following blog article: > > http://www.ntecs.de/blog/articles/2007/09/21/cplusruby-gluing-c-and-ruby > > ---------------------------------------------- > CplusRuby - Glue C and Ruby together (OO-like) > ---------------------------------------------- It's been done, but I'm glad to see it done again and probably with new ideas :) For comparison: require 'cgen/cshadow' # from cgen on RAA class NeuralEntity include CShadow attr_accessor :id end class Neuron < NeuralEntity shadow_attr_accessor :potential => "double potential" shadow_attr_accessor :last_spike_time => "double last_spike_time" shadow_attr_accessor :pre_synapses => Object define_c_method :stimulate do arguments :at, :weight body %{ shadow->potential += NUM2DBL(at)*NUM2DBL(weight); } end def initialize self.pre_synapses = [] end end NeuralEntity.commit # generate and load the shared lib if __FILE__ == $0 n = Neuron.new n.id = "n1" n.potential = 1.0 n.stimulate(1.0, 2.0) p n.potential # => 3.0 end Cgen is middle aged, as ruby libraries go (written mostly in 2001), and it probably isn't up to community standards in a number of ways. Still, I've used it intensively in numerical and hybrid simulation since then. It's the foundation for redshift, which is a DSL for simulation of hybrid automata (networked state machines with continuous as well as discrete dynamics). Cgen/cshadow handles a number of issues for you: - creating accessors (r, w, rw) - type checking and conversion in the write accessor - mark and free functions - attr initialization - persistence via marshal and yaml (or an attr may be specified non-persistent) - extensible attribute classes for defining new attr types, other than the basic numeric, string, and Ruby object types - inheritance (a subclass of a shadow class inherits the parent's shadow attrs in its own C struct; struct may be safely cast to parent type) - tools for managing how code is distributed among files (very important with a large project, or else recompilation time gets painful). - tools for managing declarations and preprocessor includes - DSL for rb_scan_args() This is pretty well documented, though it is in the old rd format, rather than rdoc. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407