diff options
author | Davide Morelli <morellid@users.sourceforge.net> | 2006-01-16 12:44:45 +0000 |
---|---|---|
committer | Davide Morelli <morellid@users.sourceforge.net> | 2006-01-16 12:44:45 +0000 |
commit | 1903f3d6e4a81d0e97fde231cbea3bad7ed96ed1 (patch) | |
tree | bd08c528ba92f7e49ff6c7c400c553aaa272214a | |
parent | 831e206a4ee3f60e6e18300d092da52a307917d9 (diff) |
added arguments at initialization time
svn path=/trunk/externals/clr/; revision=4422
-rwxr-xr-x | clr.c | 71 | ||||
-rwxr-xr-x | external/External.cs | 6 | ||||
-rwxr-xr-x | pd/Atom.cs | 6 | ||||
-rwxr-xr-x | pd/pd.cs | 7 |
4 files changed, 72 insertions, 18 deletions
@@ -106,17 +106,20 @@ static void mono_initialize() }
// load the variables and init mono
-static void mono_load(t_clr *x)
+static void mono_load(t_clr *x, int argc, t_atom *argv)
{
// const char *file="D:\\Davide\\cygwin\\home\\Davide\\externalTest1.dll"; //const char *file="External.dll"; MonoMethod *m = NULL, *ctor = NULL, *fail = NULL, *mvalues; + MonoClassField *classPointer; gpointer iter; - gpointer args [1]; + gpointer *args; int val; - int i; - + int i,j; + int params; + t_symbol *strsymbol; + atom_simple *listparams; if (x->loaded == 0) { @@ -167,7 +170,13 @@ static void mono_load(t_clr *x) return; } x->obj = mono_object_new (x->domain, x->klass); - mono_runtime_object_init (x->obj); + + //mono_runtime_object_init (x->obj); + + if (argc>2) + params = argc - 2; + else + params = 0; /* retrieve all the methods we need */ iter = NULL; @@ -185,25 +194,63 @@ static void mono_load(t_clr *x) * as you see a contrsuctor is a method like any other. */ MonoMethodSignature * sig = mono_method_signature (m); - if (mono_signature_get_param_count (sig) == 2) { + 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) { - val = x; - args [0] = &val; - mono_runtime_invoke (x->setUp, x->obj, args, NULL); + mono_runtime_invoke (x->setUp, x->obj, NULL, NULL); post("SetUp() invoked"); - } else { error("clr: the provided assembly is not valid! the SetUp function is missing"); 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; @@ -669,7 +716,7 @@ printf(" used did not specified filename, I guess it is %s\n", strtmp); }
// load mono, init the needed vars
- mono_load(x);
+ mono_load(x, argc, argv);
return (x);
}
diff --git a/external/External.cs b/external/External.cs index ace63a3..00947db 100755 --- a/external/External.cs +++ b/external/External.cs @@ -9,15 +9,11 @@ namespace PureData public External()
{
- x = IntPtr.Zero;
}
// this function MUST exist
- public void SetUp(IntPtr pdClass)
+ public void SetUp()
{
- // you must assign pdclass to x !
- x = pdClass;
-
// now you can do what you like...
Console.WriteLine("pointer set!");
Console.WriteLine("setting selectors..");
@@ -18,6 +18,12 @@ namespace PureData this.float_value = f;
this.string_value = "float";
}
+ public Atom(int i)
+ {
+ this.type = AtomType.Float;
+ this.float_value = (float) i;
+ this.string_value = "float";
+ }
public Atom(string s)
{
this.type = AtomType.Symbol;
@@ -25,7 +25,12 @@ namespace PureData {
ToOutlet (x, outlet, atoms.Length, atoms);
}
-
+ public static void SendToOutlet (IntPtr x, int outlet, Atom atom)
+ {
+ Atom [] atoms = new Atom[1];
+ atoms[0] = atom;
+ ToOutlet (x, outlet, atoms.Length, atoms);
+ }
// create an outlet
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static void CreateOutlet (IntPtr x, int type);
|