From: Chris Ross Date: 2002-02-23T00:27:03+09:00 Subject: Re: P/Invoke like system for ruby. Does this work in Mono ? Regards, Chris ----- Original Message ----- From: "Erik B�gfors" To: "ruby-talk ML" Sent: Friday, February 22, 2002 11:55 AM Subject: P/Invoke like system for ruby. Hi! Since the hottest thing to talk about right now is .NET I read up a little on it. It has this thing called P/Invoke which simply means that you can call code in dll (or .so on unix) by declaring in what library the function is and then define how the function works without using another library for wrapping that method, like you would have to with ruby. Here is a short example on how to get the "puts"-function under unix into a C# program. [DllImport("libc.so.6", EntryPoint="puts", CharSet=CharSet.Ansi)] public static extern int puts(string name); Currently in ruby you have to write wrapper-code in C, compile to a library and then require that library into your ruby-code. Would it be possible to do something like P/Invoke for ruby??? It would be really cool not having to write C-code and still be able to call functions in libraries from ruby. Here is another nice C# example to wet your appetite. [DllImport("libncurses.so", EntryPoint="initscr")] public extern static void initscr(); [DllImport("libncurses.so", EntryPoint="getch")] public extern static int getch(); [DllImport("libncurses.so", EntryPoint="mvaddstr")] public extern static void mvaddstr(int x, int y, string c); [DllImport("libncurses.so", EntryPoint="endwin")] public extern static void endwin(); [DllImport("libncurses.so", EntryPoint="refresh")] public extern static void refresh(); public static void Main() { initscr(); // Initialize ncurses mvaddstr(11, 24, "Hello, from ncurses!"); mvaddstr(12, 20, "(press any key to continue)"); refresh(); getch(); // Wait for keypress endwin(); // clean up } /Erik -- Erik B�gfors | erik@bagfors.nu Supporter of free software | GSM +46 733 279 273 fingerprint: 6666 A85B 95D3 D26B 296B 6C60 4F32 2C0B 693D 6E32