Nasal/CppBind: Difference between revisions

Jump to navigation Jump to search
m
clean up example
mNo edit summary
m (clean up example)
Line 18: Line 18:
struct Test {
struct Test {
  int x,y,z;
  int x,y,z;
void hello() {
  std::cout << "Hello World from CppBind!\n";
}
};
};


Line 23: Line 26:
typedef boost::shared_ptr<Test> Test_ptr;
typedef boost::shared_ptr<Test> Test_ptr;
typedef nasal::Ghost< Test_ptr > NasalTest;
typedef nasal::Ghost< Test_ptr > NasalTest;
// next, two helper functions that tell cppbind how to
// convert our objects between C++  <-> Nasal
naRef to_nasal_helper(naContext c, Test *src)
  {
    NasalTest_ptr ptr(src);
    return NasalTest::create(c, ptr ); //
  }
Test*
from_nasal_helper(naContext c, naRef ref, const Test*)
  { 
      NasalTest::create(c, ref); // create a new Nasal Ghost
  }


// add this to FGNasalSys::init():
// add this to FGNasalSys::init():
Line 29: Line 49:
  initNasalTest(_globals, _context);
  initNasalTest(_globals, _context);
*/
*/
// This is a helper, used by the to_helper() function
// which turns the pointers into a Nasal data structure
// so that you can return C++ classes to Nasal
naRef to_nasal_helper(naContext c, const Test& t)
  {
    nasal::Hash hash(c);
    hash.set("x", t.x );
    hash.set("y", t.y );
    hash.set("z", t.z );
    return hash.get_naRef();
  }


naRef initNasalTest(naRef globals, naContext c)
naRef initNasalTest(naRef globals, naContext c)

Navigation menu