Add nasal::Ghost class for exposing C++ classes to Nasal

This commit is contained in:
Thomas Geymayer
2012-11-12 12:11:41 +01:00
parent 9fd90e26f7
commit d31b62d44d
3 changed files with 582 additions and 2 deletions
+23 -2
View File
@@ -1,6 +1,5 @@
#include "Ghost.hxx"
#include "NasalHash.hxx"
#include "from_nasal.hxx"
#include "to_nasal.hxx"
#include <cstring>
#include <iostream>
@@ -12,6 +11,18 @@
return 1; \
}
struct Base
{
naRef member(int, naRef*) { return naNil(); }
};
struct Derived:
public Base
{
int _x;
int getX() const { return _x; }
void setX(int x) { _x = x; }
};
int main(int argc, char* argv[])
{
naContext c = naNewContext();
@@ -61,6 +72,16 @@ int main(int argc, char* argv[])
Hash mod = hash.createHash("mod");
mod.set("parent", hash);
Ghost<Base>::init("Base")
.method<&Base::member>("member");
Ghost<Derived>::init("Derived")
.bases<Base>()
.member("x", &Derived::getX, &Derived::setX);
naRef derived = Ghost<Derived>::create(c);
VERIFY( naIsGhost(derived) );
// TODO actuall do something with the ghosts...
naFreeContext(c);
return 0;