Nasal/CppBind: Difference between revisions

Jump to navigation Jump to search
no edit summary
m (clean up example)
No edit summary
Line 49: Line 49:
  initNasalTest(_globals, _context);
  initNasalTest(_globals, _context);
*/
*/
static naRef f_newtest(const nasal::CallContext& ctx)
{
  Test* t = new Test();
  t->x = 100;
  t->y = 200;
  t->z = 300;
  return ctx.to_nasal( *t );
}


naRef initNasalTest(naRef globals, naContext c)
naRef initNasalTest(naRef globals, naContext c)
Line 54: Line 64:
     NasalTest::init("Test")
     NasalTest::init("Test")
                 .method("hello", &Test::hello);
                 .method("hello", &Test::hello);
    // set up a  new namespace for our functions
    nasal::Hash globals_module(globals, c),
              test = globals_module.createHash("test");
  test.set("new", &f_new_test);


     return naNil();
     return naNil();
Line 60: Line 77:
</syntaxhighlight>
</syntaxhighlight>


Fire up the Nasal console, and run this:
<syntaxhighlight lang="nasal">
<syntaxhighlight lang="nasal">
debug.dump( test );
debug.dump( var t=test.new() );
foreach(var e; ['x','y','z']
  print t[e];
</syntaxhighlight>
</syntaxhighlight>


Navigation menu