From 5e85bcacc8ece3823ffdb35b84899cf03e943bd0 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Fri, 30 Nov 2012 00:13:16 +0100 Subject: [PATCH] Canvas: Expose more methods to Nasal. - Expose canvas::Group::getElementById to Nasal - Expose canvas::Group::getChild to Nasal --- src/Scripting/NasalCanvas.cxx | 38 ++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/Scripting/NasalCanvas.cxx b/src/Scripting/NasalCanvas.cxx index d45bf347e..df5c69363 100644 --- a/src/Scripting/NasalCanvas.cxx +++ b/src/Scripting/NasalCanvas.cxx @@ -56,16 +56,13 @@ typedef nasal::Ghost NasalCanvas; typedef nasal::Ghost NasalElement; typedef nasal::Ghost NasalGroup; -SGPropertyNode& requireArg(naContext c, int argc, naRef* args, int index = 0) +SGPropertyNode* from_nasal_helper(naContext c, naRef ref, SGPropertyNode**) { - if( argc <= index ) - naRuntimeError(c, "missing argument #%d", index); - - SGPropertyNode* props = ghostToPropNode(args[index]); + SGPropertyNode* props = ghostToPropNode(ref); if( !props ) - naRuntimeError(c, "arg #%d: not a SGPropertyNode ghost"); + naRuntimeError(c, "Not a SGPropertyNode ghost."); - return *props; + return props; } CanvasMgr& requireCanvasMgr(naContext c) @@ -91,7 +88,8 @@ static naRef f_createCanvas(naContext c, naRef me, int argc, naRef* args) */ static naRef f_getCanvas(naContext c, naRef me, int argc, naRef* args) { - SGPropertyNode& props = requireArg(c, argc, args); + nasal::CallContext ctx(c, argc, args); + SGPropertyNode& props = *ctx.requireArg(0); CanvasMgr& canvas_mgr = requireCanvasMgr(c); sc::CanvasPtr canvas; @@ -133,6 +131,24 @@ naRef f_groupCreateChild(sc::Group& group, const nasal::CallContext& ctx) ); } +naRef f_groupGetChild(sc::Group& group, const nasal::CallContext& ctx) +{ + return NasalElement::create + ( + ctx.c, + group.getChild( ctx.requireArg(0) ) + ); +} + +naRef f_groupGetElementById(sc::Group& group, const nasal::CallContext& ctx) +{ + return NasalElement::create + ( + ctx.c, + group.getElementById( ctx.requireArg(0) ) + ); +} + naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave) { NasalEvent::init("canvas.Event"); @@ -142,13 +158,15 @@ naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave) .member("_node_ghost", &elementGetNode) .member("size_x", &sc::Canvas::getSizeX) .member("size_y", &sc::Canvas::getSizeY) - .method_func<&f_canvasCreateGroup>("createGroup"); + .method_func<&f_canvasCreateGroup>("_createGroup"); NasalElement::init("canvas.Element") .member("_node_ghost", &elementGetNode) .method<&sc::Element::addEventListener>("addEventListener"); NasalGroup::init("canvas.Group") .bases() - .method_func<&f_groupCreateChild>("createChild"); + .method_func<&f_groupCreateChild>("_createChild") + .method_func<&f_groupGetChild>("_getChild") + .method_func<&f_groupGetElementById>("_getElementById"); nasal::Hash globals_module(globals, c), canvas_module = globals_module.createHash("canvas"); -- 2.39.5