- Notifications
You must be signed in to change notification settings - Fork91
PInvoke (tutorial)
You can take advantage of native platform libraries from within Nemerle programs. The syntax is very similar to C#'s and other .NET languages. Here is the simplest examlple:
using System;using System.Runtime.InteropServices;class PlatformInvokeTest{ [DllImport("msvcrt.dll")]publicexternstatic puts(c :string) :int; [DllImport("msvcrt.dll")]internalexternstatic _flushall() :int;publicstatic Main() :void {_ = puts("Test");_ = _flushall(); }}
As you can see we useDllImport attribute, which comes fromSystem.Runtime.InteropServices namespace. Every method marked with this attribute should also haveextern modifier. The concept is that the implementation of given method is substituted by call to unmanaged method from library specified insideDllImport attribute.
So, in above example, during execution ofMain method first theputs function frommsvcrt.dll will be called (printing a text to the standard output) and after that_flushall (making sure that all contents of buffer are printed).
For more seeP/Invoke tutorial from MSDN.