support for C++ code generation; importcpp and importobjc pragmas
This commit is contained in:
parent
7748dbc0b2
commit
5131b3cea4
29 changed files with 512 additions and 189 deletions
|
|
@ -1,6 +1,7 @@
|
|||
Advanced commands:
|
||||
//compileToC, cc compile project with C code generator
|
||||
//compileToOC, oc compile project to Objective C code
|
||||
//compileToCpp, cpp compile project to C++ code
|
||||
//compileToOC, objc compile project to Objective C code
|
||||
//rst2html convert a reStructuredText file to HTML
|
||||
//rst2tex convert a reStructuredText file to TeX
|
||||
//run run the project (with Tiny C backend; buggy!)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ case cast const continue converter
|
|||
discard distinct div
|
||||
elif else end enum except
|
||||
finally for from generic
|
||||
if implies import in include is isnot iterator
|
||||
if import in include is isnot iterator
|
||||
lambda let
|
||||
macro method mod
|
||||
nil not notin
|
||||
|
|
|
|||
|
|
@ -192,6 +192,85 @@ Example:
|
|||
embedsC()
|
||||
|
||||
|
||||
ImportCpp pragma
|
||||
----------------
|
||||
The `importcpp`:idx: pragma can be used to import `C++`:idx: methods. The
|
||||
generated code then uses the C++ method calling syntax: ``obj->method(arg)``.
|
||||
In addition with the ``header`` and ``emit`` pragmas this allows *sloppy*
|
||||
interfacing with libraries written in C++:
|
||||
|
||||
.. code-block:: Nimrod
|
||||
# Horrible example of how to interface with a C++ engine ... ;-)
|
||||
|
||||
{.link: "/usr/lib/libIrrlicht.so".}
|
||||
|
||||
{.emit: """
|
||||
using namespace irr;
|
||||
using namespace core;
|
||||
using namespace scene;
|
||||
using namespace video;
|
||||
using namespace io;
|
||||
using namespace gui;
|
||||
""".}
|
||||
|
||||
const
|
||||
irr = "<irrlicht/irrlicht.h>"
|
||||
|
||||
type
|
||||
TIrrlichtDevice {.final, header: irr, importc: "IrrlichtDevice".} = object
|
||||
PIrrlichtDevice = ptr TIrrlichtDevice
|
||||
|
||||
proc createDevice(): PIrrlichtDevice {.
|
||||
header: irr, importc: "createDevice".}
|
||||
proc run(device: PIrrlichtDevice): bool {.
|
||||
header: irr, importcpp: "run".}
|
||||
|
||||
|
||||
ImportObjC pragma
|
||||
-----------------
|
||||
The `importobjc`:idx: pragma can be used to import `Objective C`:idx: methods.
|
||||
The generated code then uses the Objective C method calling
|
||||
syntax: ``[obj method param1: arg]``.
|
||||
In addition with the ``header`` and ``emit`` pragmas this allows *sloppy*
|
||||
interfacing with libraries written in Objective C:
|
||||
|
||||
.. code-block:: Nimrod
|
||||
# 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()
|
||||
|
||||
|
||||
LineDir option
|
||||
--------------
|
||||
The `lineDir`:idx: option can be turned on or off. If turned on the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue