Skip to content

Instantly share code, notes, and snippets.

@Porges
Last active August 29, 2015 14:13
Show Gist options
  • Save Porges/8ef88322593a14cf4965 to your computer and use it in GitHub Desktop.
Save Porges/8ef88322593a14cf4965 to your computer and use it in GitHub Desktop.
pinvoking rust
using System;
using System.Runtime.InteropServices;
public static class Program
{
[DllImport("fact.dll")]
private static extern ulong fact(ulong x);
public static void Main()
{
Console.WriteLine(fact(13));
}
}
#![crate_type = "lib"]
#[no_mangle]
pub extern fn fact(x: u64) -> u64 {
match x {
0 => 1,
_ => x * fact(x-1),
}
}
open System.Runtime.InteropServices
[<DllImport("fact.dll")>]
extern uint64 fact(uint64)
[<EntryPoint>]
let main argv =
printfn "%u" <| fact 13UL
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment