diff options
author | Araq <rumpf_a@web.de> | 2011-08-07 21:02:09 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-08-07 21:02:09 +0200 |
commit | 5131b3cea4ba50970ef5d3313cbd8a75acadc2d7 (patch) | |
tree | 28391aa51f7011e381da3c23cd3aee483a78e4a6 /examples/objciface/gnustepex.nim | |
parent | 7748dbc0b24756459e25e2f9f55a219f7d3faf50 (diff) | |
download | Nim-5131b3cea4ba50970ef5d3313cbd8a75acadc2d7.tar.gz |
support for C++ code generation; importcpp and importobjc pragmas
Diffstat (limited to 'examples/objciface/gnustepex.nim')
-rw-r--r-- | examples/objciface/gnustepex.nim | 40 |
1 files changed, 40 insertions, 0 deletions
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 <objc/Object.h> + +@interface Greeter:Object +{ +} + +- (void)greet:(long)x y:(long)dummy; + +@end + +#include <stdio.h> + +@implementation Greeter + +- (void)greet:(long)x y:(long)dummy +{ + printf("Hello, World!\n"); +} + +@end + +#include <stdlib.h> +""".} + +type + TId {.importc: "id", header: "<objc/Object.h>", 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() + |