From 7a0d21c028c073e0ff3c64ab0bd7958e79816d45 Mon Sep 17 00:00:00 2001 From: Davide Morelli Date: Fri, 13 Jan 2006 13:02:22 +0000 Subject: single atom ok, no luck with arrays svn path=/trunk/externals/clr/; revision=4399 --- clr.c | 36 ++++++++++++++++++++++++++++-------- external/External.cs | 16 ++++++++-------- external/pd.cs | 26 +++++++++++++++++++++----- 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/clr.c b/clr.c index bdafd74..28ad5e9 100755 --- a/clr.c +++ b/clr.c @@ -49,6 +49,7 @@ typedef enum A_S_FLOAT=1, A_S_SYMBOL=2, } t_atomtype_simple; + typedef struct atom_simple { //t_atomtype_simple a_type; @@ -60,6 +61,13 @@ typedef struct atom_simple //} stuff; }; +/* +typedef struct atom_simple +{ + int a; + int b; +}; +*/ static t_class *clr_class; @@ -303,7 +311,10 @@ void clr_manage_list(t_clr *x, t_symbol *sl, int argc, t_atom *argv) int *tipo; float *fp; - MonoClass *c = mono_class_from_name (x->image, "PureData", "Atom"); + MonoClass *c = mono_class_from_name (x->image, "PureData", "Atom2"); + if (!c) + error("----> can't find Atom"); + //arystr = mono_array_new (x->domain, atom_simple, argc); arystr = mono_array_new (x->domain, c /*mono_get_string_class ()*/, argc); //arystr = mono_array_new (x->domain, c, 2); /* @@ -353,14 +364,23 @@ post("setting type null in position %i", j); // debug: // send just 1 atom - atmp2 = malloc(sizeof(atom_simple)); - atmp2->a_type = 121; - atmp2->float_value = atom_getfloat(argv); - strsymbol = atom_getsymbol(argv); - atmp2->string_value = mono_string_new (x->domain, strsymbol->s_name); - args[0] = atmp2; + atmp2 = malloc(sizeof(atom_simple)); + atmp2->a_type = 121; + atmp2->float_value = atom_getfloat(argv); + strsymbol = atom_getsymbol(argv); +printf("strsymbol->s_name = %s\n", strsymbol->s_name); + atmp2->string_value = mono_string_new (x->domain, strsymbol->s_name); + args[0] = atmp2; + + /* + atmp2 = malloc(sizeof(atom_simple)); + atmp2->a = 121; + atmp2->b = 1; + args[0] = atmp2; + */ + /* // a list of atoms for (j=0; jstring_value = mono_string_new (x->domain, strtmp2); mono_array_set (arystr, atom_simple *, 1, atmp3); */ - // args[0] = arystr; + //args[0] = arystr; //args[0] = strings; mono_runtime_invoke (x->selectors[i].func, x->obj, args, NULL); diff --git a/external/External.cs b/external/External.cs index f09487d..215461c 100755 --- a/external/External.cs +++ b/external/External.cs @@ -41,7 +41,6 @@ namespace PureData - public void Sel1() { pd.PostMessage("Sel1 invoked!"); @@ -92,11 +91,14 @@ namespace PureData public void SelGenericList(Atom a) { - Console.WriteLine("a is type " + a.type); - Console.WriteLine("float = " + a.float_value); - Console.WriteLine("stringa = " + a.string_value); + + Console.WriteLine("a is type " + a.type); + Console.WriteLine("float = " + a.float_value); + Console.WriteLine("stringa = " + a.string_value); + } + /* public void SelGenericList(Atom [] list) { @@ -110,11 +112,9 @@ namespace PureData pd.PostMessage("a is type " + a.type); pd.PostMessage("float = " + a.float_value); pd.PostMessage("stringa = " + a.string_value); - - } - + } } -*/ +*/ public int test(int a) { diff --git a/external/pd.cs b/external/pd.cs index 33f7f1f..4f05734 100755 --- a/external/pd.cs +++ b/external/pd.cs @@ -68,17 +68,18 @@ typedef struct atom_simple }; */ - public enum AtomType {Null = 0, Float=1, Symbol=2}; + public enum AtomType {Null = 0, Float=1, Symbol=2, List=3}; + [StructLayout (LayoutKind.Explicit)] // [StructLayout (LayoutKind.Sequential)] - public class Atom + public class Atom2 { //[FieldOffset (0)] AtomType type; //[FieldOffset (0)] public int type; [FieldOffset (0)] public int type; - /* union members */ + [FieldOffset (4)] public float float_value; @@ -87,22 +88,37 @@ typedef struct atom_simple public string string_value; + public Atom2() + { + this.type = 0; + this.float_value = 0; + this.string_value = ""; + } - public Atom(string string_value) + public Atom2(string string_value) { this.type = 2; this.float_value = 0; this.string_value = string_value; } - public Atom(float float_value) + public Atom2(float float_value) { this.type = 1; this.string_value = ""; this.float_value = float_value; } } + + //[StructLayout (LayoutKind.Explicit)] + [StructLayout (LayoutKind.Sequential)] + public struct Atom + { + public int type; + public float float_value; + public string string_value; + } /* typedef float t_floatarg; -- cgit v1.2.1