From 5131b3cea4ba50970ef5d3313cbd8a75acadc2d7 Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 7 Aug 2011 21:02:09 +0200 Subject: support for C++ code generation; importcpp and importobjc pragmas --- examples/objciface/gnustepex.nim | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/objciface/gnustepex.nim (limited to 'examples/objciface') diff --git a/examples/objciface/gnustepex.nim b/examples/objciface/gnustepex.nim new file mode 100644 index 000000000..d961d3087 --- /dev/null +++ b/examples/objciface/gnustepex.nim @@ -0,0 +1,40 @@ +# horrible example of how to interface with GNUStep ... + +{.passL: "-lobjc".} +{.emit: """ + +#include + +@interface Greeter:Object +{ +} + +- (void)greet:(long)x y:(long)dummy; + +@end + +#include + +@implementation Greeter + +- (void)greet:(long)x y:(long)dummy +{ + printf("Hello, World!\n"); +} + +@end + +#include +""".} + +type + TId {.importc: "id", header: "", final.} = distinct int + +proc newGreeter: TId {.importobjc: "Greeter new", nodecl.} +proc greet(self: TId, x, y: int) {.importobjc: "greet", nodecl.} +proc free(self: TId) {.importobjc: "free", nodecl.} + +var g = newGreeter() +g.greet(12, 34) +g.free() + -- cgit 1.4.1-2-gfad0