[Gridflow-cvs] [svn] commit: r3589 - in /trunk: base/flow_objects.c base/grid.h base/source_filter.rb rubyext.c

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Fri Apr 18 10:59:21 EDT 2008


Author: matju
Date: Fri Apr 18 10:59:20 2008
New Revision: 3589

Log:
\startup receives FClass* instead of Ruby class; merged FClass2 into FClass

Modified:
    trunk/base/flow_objects.c
    trunk/base/grid.h
    trunk/base/source_filter.rb
    trunk/rubyext.c

Modified: trunk/base/flow_objects.c
==============================================================================
--- trunk/base/flow_objects.c (original)
+++ trunk/base/flow_objects.c Fri Apr 18 10:59:20 2008
@@ -2575,7 +2575,7 @@
 }
 \end class {
 	install("display",1,0);
-	t_class *qlass = fclasses_ruby[rself]->bfclass;
+	t_class *qlass = fclass->bfclass;
 	t_widgetbehavior *wb = new t_widgetbehavior;
 	wb->w_getrectfn    = display_getrectfn;
 	wb->w_displacefn   = display_displacefn;

Modified: trunk/base/grid.h
==============================================================================
--- trunk/base/grid.h (original)
+++ trunk/base/grid.h Fri Apr 18 10:59:20 2008
@@ -367,11 +367,6 @@
 }
 
 //****************************************************************
-// CObject is the base class for C++ classes that get exported to Ruby.
-// BTW: It's quite convenient to have virtual-methods in the base class
-// because otherwise the vtable* isn't at the beginning of the object
-// and that's pretty confusing to a lot of people, especially when simple
-// casting causes a pointer to change its value.
 
 struct CObject {
 	int32 refcount;
@@ -824,10 +819,17 @@
 #define MESSAGE2 sel,argc,argv
 struct FClass {
 	void *(*allocator)(MESSAGE); // returns a new C++ object
-	void (*startup)(Ruby rself); // initializer for the Ruby class
-	const char *name; // C++/Ruby name (not PD name)
+	void (*startup)(FClass *);
+	const char *rubyname; // C++/Ruby name (not PD name)
 	int methodsn; MethodDecl *methods; // C++ -> Ruby methods
-};
+
+	int ninlets;
+	int noutlets;
+	t_class *bfclass;
+	string name;
+	Ruby rself;
+};
+
 void fclass_install(FClass *fc, const char *super);
 
 //****************************************************************
@@ -955,10 +957,10 @@
 
 void suffixes_are (const char *name, const char *suffixes);
 
-#define install(name,inlets,outlets) install2(rself,name,inlets,outlets)
-void install2(Ruby rself, const char *name, int inlets, int outlets);
-#define add_creator(name) add_creator2(rself,name)
-void add_creator2(Ruby rself, const char *name);
+#define install(name,inlets,outlets) install2(fclass,name,inlets,outlets)
+void install2(FClass *fclass, const char *name, int inlets, int outlets);
+#define add_creator(name) add_creator2(fclass,name)
+void add_creator2(FClass *fclass, const char *name);
 
 #define install_format(name,mode,suffixes) do {install(name,1,1); suffixes_are(name,suffixes);} while(0)
 
@@ -972,7 +974,6 @@
 	NumberTypeE cast;
 	long frame;
 	Format(MESSAGE) : GridObject(MESSAGE2), mode(0), fd(-1), f(0), cast(int32_e), frame(0) {}
-	\decl void initialize (t_symbol *mode, ...);
 	\decl 0 open (t_symbol *mode, string filename);
 	\decl 0 close ();
 	\decl 0 cast (NumberTypeE nt);
@@ -996,15 +997,8 @@
 inline void set_atom (t_atom *a, Numop    *v) {SETSYMBOL(a,v->sym);}
 inline void set_atom (t_atom *a, t_binbuf *v) {SETLIST(a,v);}
 
-struct FClass2 {
-	int ninlets;
-	int noutlets;
-	t_class *bfclass;
-	string name;
-	Ruby rself;
-};
-extern std::map<string,FClass2 *> fclasses;
-extern std::map<Ruby,FClass2 *> fclasses_ruby;
+extern std::map<string,FClass *> fclasses;
+extern std::map<Ruby,FClass *> fclasses_ruby;
 int handle_braces(int ac, t_atom *av);
 void ruby2pd (int argc, Ruby *argv, t_atom *at);
 void pd2ruby (int argc, Ruby *argv, t_atom *at);

Modified: trunk/base/source_filter.rb
==============================================================================
--- trunk/base/source_filter.rb (original)
+++ trunk/base/source_filter.rb Fri Apr 18 10:59:20 2008
@@ -219,7 +219,7 @@
 	frame = $stack[-1]
 	cl = frame.name
 	line="{}" if /^\s*$/ =~ line
-	Out.print "static void #{cl}_startup (Ruby rself);"
+	Out.print "static void #{cl}_startup (FClass *fclass);"
 	Out.print "static void *#{cl}_allocator (MESSAGE) {return new #{cl}(sel,argc,argv);}"
 	Out.print "static MethodDecl #{cl}_methods[] = {"
 	Out.print frame.methods.map {|foo,method|
@@ -246,7 +246,8 @@
 	line.gsub!(/^\s*(\w+\s*)?\{/,"")
 	get << "RAISE(\"unknown attr %s\",s->s_name); outlet_anything(bself->out[bself->nout-1],s,1,a);}"
 	handle_def get if frame.attrs.size>0
-	Out.print "void #{frame.name}_startup (Ruby rself) {IEVAL(rself,\"#{startup2}\");"+line.chomp
+	# "IEVAL(rself,\"#{startup2}\");" # this means no support for attributes for a while.
+	Out.print "void #{frame.name}_startup (FClass *fclass) {"+line.chomp
 end
 
 def handle_grin(line)

Modified: trunk/rubyext.c
==============================================================================
--- trunk/rubyext.c (original)
+++ trunk/rubyext.c Fri Apr 18 10:59:20 2008
@@ -60,8 +60,8 @@
 // call f(x) and if fails call g(y)
 #define RESCUE(f,x,g,y) rb_rescue2((RMethod)(f),(Ruby)(x),(RMethod)(g),(Ruby)(y),rb_eException,0);
 
-std::map<string,FClass2 *> fclasses;
-std::map<Ruby,FClass2 *> fclasses_ruby;
+std::map<string,FClass *> fclasses;
+std::map<Ruby,FClass *> fclasses_ruby;
 
 /* **************************************************************** */
 struct BFObject;
@@ -402,10 +402,8 @@
 	BFObject_redraw(this);
 }
 
-void add_creator2(Ruby rself, const char *name) {
-	if (fclasses_ruby.find(rself)==fclasses_ruby.end()) RAISE("uh");
-	string fname = fclasses_ruby[rself]->name;
-	fclasses[string(name)] = fclasses[fname];
+void add_creator2(FClass *fclass, const char *name) {
+	fclasses[string(name)] = fclass;
 	class_addcreator((t_newmethod)BFObject_init,gensym((char *)name),A_GIMME,0);
 }
 
@@ -442,21 +440,20 @@
 	}
 }
 
-void fclass_install(FClass *fc, const char *super) {
-	Ruby rself = super ?
-		rb_define_class_under(mGridFlow, fc->name, rb_funcall(mGridFlow,SI(const_get),1,rb_str_new2(super))) :
-		rb_funcall(mGridFlow,SI(const_get),1,rb_str_new2(fc->name));
-	define_many_methods(rself,fc->methodsn,fc->methods);
-	rb_ivar_set(rself,SI(@allocator),PTR2FIX((void*)(fc->allocator)));
-	if (fc->startup) fc->startup(rself);
-}
-
-void install2(Ruby rself, const char *name, int inlets, int outlets) {
-	FClass2 *fclass = fclasses_ruby[rself] = new FClass2;
+void fclass_install(FClass *fclass, const char *super) {
+	fclass->rself = super ?
+		rb_define_class_under(mGridFlow, fclass->rubyname, rb_funcall(mGridFlow,SI(const_get),1,rb_str_new2(super))) :
+		rb_funcall(mGridFlow,SI(const_get),1,rb_str_new2(fclass->rubyname));
+	define_many_methods(fclass->rself,fclass->methodsn,fclass->methods);
+	rb_ivar_set(fclass->rself,SI(@allocator),PTR2FIX((void*)(fclass->allocator)));
+	if (fclass->startup) fclass->startup(fclass);
+}
+
+void install2(FClass *fclass, const char *name, int inlets, int outlets) {
+	fclasses_ruby[fclass->rself] = fclass;
 	fclass->ninlets = inlets;
 	fclass->noutlets = outlets;
 	fclass->name = string(name);
-	fclass->rself = rself;
 	fclass->bfclass = class_new(gensym((char *)name), (t_newmethod)BFObject_init, (t_method)BFObject_delete,
 		sizeof(BFObject), CLASS_DEFAULT, A_GIMME,0);
 	fclasses[string(name)] = fclass;



More information about the Gridflow-cvs mailing list