Last active
August 29, 2015 14:13
-
-
Save Porges/8ef88322593a14cf4965 to your computer and use it in GitHub Desktop.
pinvoking rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![crate_type = "lib"] | |
#[no_mangle] | |
pub extern fn fact(x: u64) -> u64 { | |
match x { | |
0 => 1, | |
_ => x * fact(x-1), | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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