Skip to content

Instantly share code, notes, and snippets.

@ymurase
Last active August 29, 2015 14:12
Show Gist options
  • Save ymurase/d1b19b7e8fc78485b1eb to your computer and use it in GitHub Desktop.
Save ymurase/d1b19b7e8fc78485b1eb to your computer and use it in GitHub Desktop.
x10でNativeのコードを呼ぶ。ミニマム実装
import x10.compiler.Native;
public class Test {
@Native("c++", "printf(\"Hello world.\\n\")")
private static native def test2(): void;
// Use function parameters
// #0 : name of the class (Test)
// #1,#2,#3,...: parameters
@Native("c++", "printf(\"This is the number %d\\n\", (#1) )" )
private static native def test3(x: Int): void;
public static def main(args:Rail[String]) {
test2();
test3(30n);
// direct access
val x = 42;
{
@Native("c++", "std::cout << x << std::endl;") {}
// 最後の{}がないと実行されない
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment