[PD-cvs] externals/clr clr.c,1.7,1.8

dmorelli morellid at users.sourceforge.net
Mon Jan 16 13:44:47 CET 2006


Update of /cvsroot/pure-data/externals/clr
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15459

Modified Files:
	clr.c 
Log Message:
added arguments at initialization time

Index: clr.c
===================================================================
RCS file: /cvsroot/pure-data/externals/clr/clr.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** clr.c	16 Jan 2006 11:30:26 -0000	1.7
--- clr.c	16 Jan 2006 12:44:44 -0000	1.8
***************
*** 107,111 ****
  
  // load the variables and init mono
! static void mono_load(t_clr *x)
  {
  //	const char *file="D:\\Davide\\cygwin\\home\\Davide\\externalTest1.dll";
--- 107,111 ----
  
  // load the variables and init mono
! static void mono_load(t_clr *x, int argc, t_atom *argv)
  {
  //	const char *file="D:\\Davide\\cygwin\\home\\Davide\\externalTest1.dll";
***************
*** 113,121 ****
  	
  	MonoMethod *m = NULL, *ctor = NULL, *fail = NULL, *mvalues;
  	gpointer iter;
! 	gpointer args [1];
  	int val;
! 	int i;
! 
  
  	if (x->loaded == 0)
--- 113,124 ----
  	
  	MonoMethod *m = NULL, *ctor = NULL, *fail = NULL, *mvalues;
+ 	MonoClassField *classPointer;
  	gpointer iter;
! 	gpointer *args;
  	int val;
! 	int i,j;
! 	int params;
! 	t_symbol *strsymbol;
! 	atom_simple *listparams;
  
  	if (x->loaded == 0)
***************
*** 168,172 ****
  	}
  	x->obj = mono_object_new (x->domain, x->klass);
! 	mono_runtime_object_init (x->obj);
  
  	/* retrieve all the methods we need */
--- 171,181 ----
  	}
  	x->obj = mono_object_new (x->domain, x->klass);
! 	
! 	//mono_runtime_object_init (x->obj);
! 
! 	if (argc>2)
! 		params = argc - 2;
! 	else
! 		params = 0;
  
  	/* retrieve all the methods we need */
***************
*** 186,203 ****
  			 */
  			MonoMethodSignature * sig = mono_method_signature (m);
! 			if (mono_signature_get_param_count (sig) == 2) {
  				ctor = m;
  			}
  		}
  	}
! 
  	// call the base functions
  	if (x->setUp)
  	{
! 		val = x;
! 		args [0] = &val;
! 		mono_runtime_invoke (x->setUp, x->obj, args, NULL);
  		post("SetUp() invoked");
- 
  	} else
  	{
--- 195,220 ----
  			 */
  			MonoMethodSignature * sig = mono_method_signature (m);
! 			if (mono_signature_get_param_count (sig) == params) {
  				ctor = m;
  			}
  		}
  	}
! 	// set the pointer
! 	classPointer = 0;
! 	classPointer = mono_class_get_field_from_name (x->klass, "x");
! 	if (classPointer)
! 	{
! 		mono_field_set_value (x->obj, classPointer, &x);
! 		
! 	} else
! 	{
! 		error("could not find the x field in %s, it is needed!", x->assemblyname->s_name);
! 		return;
! 	}
  	// call the base functions
  	if (x->setUp)
  	{
! 		mono_runtime_invoke (x->setUp, x->obj, NULL, NULL);
  		post("SetUp() invoked");
  	} else
  	{
***************
*** 205,208 ****
--- 222,255 ----
  		return;
  	}
+ 	// now call the class constructor
+ 	if (ctor)
+ 	{
+ 		args = malloc(sizeof(gpointer)*params);
+ 		listparams = malloc(sizeof(atom_simple)*params);
+ 		for (j=2; j<argc; j++)
+ 		{
+ 			switch ((argv+j)->a_type)
+ 			{
+ 			case A_FLOAT:
+ 				listparams[j-2].a_type =  A_S_FLOAT;
+ 				listparams[j-2].float_value = (double) atom_getfloat(argv+j);
+ 				args[j-2] = &(listparams[j-2].float_value);
+ 				break;
+ 			case A_SYMBOL:
+ 				listparams[j-2].a_type =  A_S_SYMBOL;
+ 				strsymbol = atom_getsymbol(argv+j);
+ 				listparams[j-2].string_value = mono_string_new (x->domain, strsymbol->s_name);
+ 				args[j-2] = listparams[j-2].string_value;
+ 				break;
+ 			}
+ 		}
+ 		mono_runtime_invoke (ctor, x->obj, args, NULL);
+ 		free(listparams);
+ 		free(args);
+ 	} else
+ 	{
+ 		error("%s doesn't have a constructor with %i parameters!",x->assemblyname->s_name, params);
+ 	}
+ 
  	// all done without errors
  	x->loaded = 1;
***************
*** 670,674 ****
  
  	// load mono, init the needed vars
! 	mono_load(x);
  
      return (x);
--- 717,721 ----
  
  	// load mono, init the needed vars
! 	mono_load(x, argc, argv);
  
      return (x);





More information about the Pd-cvs mailing list