Nasal/CppBind: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
No edit summary
mNo edit summary
Line 2: Line 2:
Open $FG_SRC/Scripting/CMakeLists.txt and add these entries to the SOURCES/HEADER section respectively:
Open $FG_SRC/Scripting/CMakeLists.txt and add these entries to the SOURCES/HEADER section respectively:
* NasalTest.cxx (SOURCES)
* NasalTest.cxx (SOURCES)
* NasalTest.hxx
* NasalTest.hxx (HEADERS)


Next, create the NasalTest.cxx source file:
Next, create the NasalTest.cxx source file:
Line 13: Line 13:
#include <simgear/nasal/cppbind/Ghost.hxx>
#include <simgear/nasal/cppbind/Ghost.hxx>
   
   
# the struct we want to expose to Nasal
# the struct we want to expose to Nasal (could also be a class obviously)
struct Test {
struct Test {
  static double x,y,z;
  int x,y,z;
};
};


// cppbind manages all objects as shared pointers, use boost::shared_ptr or SGReferenced objects
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;
Line 26: Line 27:
  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