[Mono-list] cilc CIL-to-C binding generator now in CVS

fd fd0h1440@yahoo.co.uk
25 Apr 2003 00:59:28 +0100


cilc is a CIL-to-C binding generator. It can be used to expose any CIL library
to the C (and C++) world using the GObject object model and coding style. This
should be of particular interest to GNOME developers who wish to make use of
libraries developed in C#, perhaps Gtk# widgets, within their own C
applications. Developers who use a generated binding need no specific knowledge
pertaining to Mono and runtime embedding -- almost everything is done behind
the scenes.

Right now, cilc is in an early stage of development. See TODO for a list of
pending tasks.

For a demonstration, see Test.cs and demo.c to get an idea of what's going on.
Then run:

$ make test
$ cd generated
$ ./demo
c# static method invoked
c# ctor invoked
c# instance method invoked
c# method with an unusual name invoked

cilc can be found in in mcs/tools/cilc. It will only work with the mini
embedding API, which is now the default.


demo.c:

#include "demo.h"

int main () {
  DemoTest *my_test;

  //run a static method
  demo_test_static_method ();

  //create an object instance
  my_test = demo_test_new ();

  //run an instance method
  demo_test_method1 (my_test);

  //run an instance method with an unusual name
  demo_test_gtype_gtype_gtype (my_test);

  //TODO: run an instance method with arguments
  //demo_test_method2 (my_test, "hey");
}


Test.cs:

namespace Demo
{
        using System;

        public class Test
        {
                string inner;

                public Test ()
                {
                        Console.WriteLine ("c# ctor invoked");
                        inner = "c# instance method invoked";
                }

                public static void StaticMethod ()
                {
                        Console.WriteLine ("c# static method invoked");
                }

                public void Method1 ()
                {
                        Console.WriteLine (inner);
                }

                public void Method2 (string arg1)
                {
                        Console.WriteLine (arg1);
                }

                public void Method3 (string arg1, int arg2)
                {
                        Console.WriteLine (arg1 + arg2.ToString ());
                }

                public void GTypeGTypeGType ()
                {
                        Console.WriteLine ("c# method with an unusual
name invoked");
                }
        }
}