2005-12-22 Alp Toker <alp@atoker.com>
authorAlp Toker <alp@mono-cvs.ximian.com>
Thu, 22 Dec 2005 17:55:49 +0000 (17:55 -0000)
committerAlp Toker <alp@mono-cvs.ximian.com>
Thu, 22 Dec 2005 17:55:49 +0000 (17:55 -0000)
  * cilc.cs: Add support for string return types and properties
  * Test.cs, demo.c: Update tests

svn path=/trunk/mcs/; revision=54746

mcs/tools/cilc/ChangeLog
mcs/tools/cilc/Test.cs
mcs/tools/cilc/cilc.cs
mcs/tools/cilc/demo.c

index ca86f5d328e94411f02c6cb8904885131e4127e5..d5aece2d53402ee7d21f25e2738e1231b6913e16 100644 (file)
@@ -1,3 +1,8 @@
+2005-12-22  Alp Toker  <alp@atoker.com>
+
+       * cilc.cs: Add support for string return types and properties
+       * Test.cs, demo.c: Update tests
+
 2005-12-22  Alp Toker  <alp@atoker.com>
 
        * cilc.cs: Add support for char, sbyte, byte and double
index 18ba253819b929ebbcc7968d5a4d6986d655266e..3de9a17cc8b82a03c169267a359af17487e0675b 100644 (file)
@@ -51,7 +51,7 @@ namespace Demo
 
                public double GetDoubleValue ()
                {
-                       return (double)counter;
+                       return (double)counter/2;
                }
 
                public int GetValue ()
@@ -75,6 +75,11 @@ namespace Demo
                        Console.WriteLine ("string: " + arg1string);
                }
 
+               public string MakeUpper (string arg1string)
+               {
+                       return arg1string.ToUpper ();
+               }
+
                public void Method4 (string arg1string, int arg2int)
                {
                        Console.WriteLine (arg1string + arg2int.ToString ());
index 4039dfe418a68177c82123d3f2ca3f59b19ce9bd..00e5c45cc99d06d8deab0630b5928d3ce9b60f28 100644 (file)
@@ -1101,6 +1101,10 @@ public class cilc
                                        C.WriteLine (rettype + "* retval = (" + rettype + "*) mono_object_unbox (mono_runtime_invoke (_mono_method, " + mono_obj + ", " + params_arg + ", NULL));");
                                        C.WriteLine ("return (" + rettype + ") *retval;");
                                        C.WriteLine ("}");
+                               } else if (rettype == "const gchar *")
+                               {
+                                       //convert the MonoString to a UTF8 before returning
+                                       C.WriteLine ("return (" + rettype + ") mono_string_to_utf8 ((MonoString*) mono_runtime_invoke (_mono_method, " + mono_obj + ", " + params_arg + ", NULL));");
                                } else {
                                        //TODO: this isn't right
                                        C.WriteLine ("return (" + rettype + ") mono_runtime_invoke (_mono_method, " + mono_obj + ", " + params_arg + ", NULL);");
index 813ab9a6ff4bee4fb5876f50df4212bec9c82ba6..acb6e60afc6acd52f56983469815bbc1aa30d934 100644 (file)
@@ -4,7 +4,7 @@
 
 int main () {
   DemoTest *my_test;
-       //gchar *tmp;
+       const gchar *mystr;
        int num;
        gdouble num_dbl;
        DemoDrink drink;
@@ -25,12 +25,17 @@ int main () {
   //run an instance method with arguments
   demo_test_echo (my_test, "hello from c");
 
+  //run an instance method with arguments and a return string
+  mystr = demo_test_make_upper (my_test, "lower to upper");
+       g_printf ("Lower to upper: %s\n", mystr);
+
   //run a property set accessor
   demo_test_set_title (my_test, "set property from c");
   
-       //run a property set accessor
-  //tmp = demo_test_get_title (my_test);
-       //g_print (tmp);
+       //run a property get accessor
+  mystr = demo_test_get_title (my_test);
+       g_printf ("Title property: %s\n", mystr);
+
   num = demo_test_get_value (my_test);
        g_printf ("The counter's value is %d\n", num);