From 3c0b7f88b80f7d5044d6f734968d7f9568668ccc Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Tue, 3 Jun 2014 02:23:17 +0200 Subject: [PATCH] Updates for simgear nasal::Ghost changes. --- src/GUI/FileDialog.cxx | 2 +- src/Scripting/NasalCanvas.cxx | 73 ++++++----------------- src/Scripting/NasalPositioned_cppbind.cxx | 12 ++-- src/Scripting/NasalSys.cxx | 2 +- 4 files changed, 27 insertions(+), 62 deletions(-) diff --git a/src/GUI/FileDialog.cxx b/src/GUI/FileDialog.cxx index f7dfcc116..e8fdc3724 100644 --- a/src/GUI/FileDialog.cxx +++ b/src/GUI/FileDialog.cxx @@ -154,7 +154,7 @@ static naRef f_createFileDialog(naContext c, naRef me, int argc, naRef* args) FileDialogPtr fd(new PUIFileDialog(usage)); #endif - return NasalFileDialog::create(c, fd); + return nasal::to_nasal(c, fd); } void postinitNasalGUI(naRef globals, naContext c) diff --git a/src/Scripting/NasalCanvas.cxx b/src/Scripting/NasalCanvas.cxx index b3dae9671..4da6b5a23 100644 --- a/src/Scripting/NasalCanvas.cxx +++ b/src/Scripting/NasalCanvas.cxx @@ -73,7 +73,7 @@ typedef nasal::Ghost NasalText; typedef nasal::Ghost NasalLayoutItem; typedef nasal::Ghost NasalLayout; -typedef nasal::Ghost NasalWindow; +typedef nasal::Ghost NasalWindow; naRef to_nasal_helper(naContext c, const osg::BoundingBox& bb) { @@ -95,11 +95,6 @@ SGPropertyNode* from_nasal_helper(naContext c, naRef ref, SGPropertyNode**) return props; } -sc::CanvasWeakPtr from_nasal_helper(naContext c, naRef ref, sc::CanvasWeakPtr const*) -{ - return nasal::from_nasal(c, ref); -} - CanvasMgr& requireCanvasMgr(naContext c) { CanvasMgr* canvas_mgr = @@ -125,7 +120,7 @@ GUIMgr& requireGUIMgr(naContext c) */ static naRef f_createCanvas(const nasal::CallContext& ctx) { - return NasalCanvas::create(ctx.c, requireCanvasMgr(ctx.c).createCanvas()); + return ctx.to_nasal(requireCanvasMgr(ctx.c).createCanvas()); } /** @@ -133,7 +128,7 @@ static naRef f_createCanvas(const nasal::CallContext& ctx) */ static naRef f_createWindow(const nasal::CallContext& ctx) { - return NasalWindow::create + return nasal::to_nasal ( ctx.c, requireGUIMgr(ctx.c).createWindow( ctx.getArg(0) ) @@ -166,16 +161,12 @@ static naRef f_getCanvas(naContext c, naRef me, int argc, naRef* args) canvas = canvas_mgr.getCanvas( props.getIntValue("index") ); } - return NasalCanvas::create(c, canvas); + return nasal::to_nasal(c, canvas); } naRef f_canvasCreateGroup(sc::Canvas& canvas, const nasal::CallContext& ctx) { - return NasalGroup::create - ( - ctx.c, - canvas.createGroup( ctx.getArg(0) ) - ); + return ctx.to_nasal( canvas.createGroup(ctx.getArg(0)) ); } /** @@ -183,35 +174,18 @@ naRef f_canvasCreateGroup(sc::Canvas& canvas, const nasal::CallContext& ctx) */ naRef f_getDesktop(naContext c, naRef me, int argc, naRef* args) { - return NasalGroup::create(c, requireGUIMgr(c).getDesktop()); + return nasal::to_nasal(c, requireGUIMgr(c).getDesktop()); } -naRef f_groupCreateChild(sc::Group& group, const nasal::CallContext& ctx) +static naRef f_groupCreateChild(sc::Group& group, const nasal::CallContext& ctx) { - return NasalElement::create - ( - ctx.c, - group.createChild( ctx.requireArg(0), - ctx.getArg(1) ) - ); + return ctx.to_nasal( group.createChild( ctx.requireArg(0), + ctx.getArg(1) ) ); } -naRef f_groupGetChild(sc::Group& group, const nasal::CallContext& ctx) +static sc::ElementPtr f_groupGetChild(sc::Group& group, SGPropertyNode* node) { - 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) ) - ); + return group.getChild(node); } static void propElementSetData( simgear::PropertyBasedElement& el, @@ -319,10 +293,7 @@ static naRef f_createCustomEvent(const nasal::CallContext& ctx) detail = ctx.from_nasal(na_detail); } - return NasalCustomEvent::create( - ctx.c, - sc::CustomEventPtr(new sc::CustomEvent(type, detail)) - ); + return ctx.to_nasal( sc::CustomEventPtr(new sc::CustomEvent(type, detail)) ); } struct CustomEventDetailWrapper: @@ -370,16 +341,6 @@ static naRef f_customEventGetDetail( sc::CustomEvent& event, ); } -naRef to_nasal_helper(naContext c, const sc::ElementWeakPtr& el) -{ - return NasalElement::create(c, el.lock()); -} - -naRef to_nasal_helper(naContext c, const sc::CanvasWeakPtr& canvas) -{ - return NasalCanvas::create(c, canvas.lock()); -} - template static naRef f_newAsBase(const nasal::CallContext& ctx) { @@ -445,7 +406,10 @@ naRef initNasalCanvas(naRef globals, naContext c) .member("size_y", &sc::Canvas::getSizeY) .method("_createGroup", &f_canvasCreateGroup) .method("_getGroup", &sc::Canvas::getGroup) - .method("addEventListener", &sc::Canvas::addEventListener) + .method( "addEventListener", + static_cast + (&sc::Canvas::addEventListener) ) .method("dispatchEvent", &sc::Canvas::dispatchEvent); canvas_module.set("_newCanvasGhost", f_createCanvas); @@ -460,11 +424,12 @@ naRef initNasalCanvas(naRef globals, naContext c) .method("dispatchEvent", &sc::Element::dispatchEvent) .method("getBoundingBox", &sc::Element::getBoundingBox) .method("getTightBoundingBox", &sc::Element::getTightBoundingBox); + NasalGroup::init("canvas.Group") .bases() .method("_createChild", &f_groupCreateChild) - .method("_getChild", &f_groupGetChild) - .method("_getElementById", &f_groupGetElementById); + .method( "_getChild", &f_groupGetChild) + .method("_getElementById", &sc::Group::getElementById); NasalText::init("canvas.Text") .bases() .method("getNearestCursor", &sc::Text::getNearestCursor); diff --git a/src/Scripting/NasalPositioned_cppbind.cxx b/src/Scripting/NasalPositioned_cppbind.cxx index 9f3a1968c..7ef63d02c 100644 --- a/src/Scripting/NasalPositioned_cppbind.cxx +++ b/src/Scripting/NasalPositioned_cppbind.cxx @@ -131,12 +131,12 @@ static naRef f_airport_comms(FGAirport& apt, const nasal::CallContext& ctx) } //------------------------------------------------------------------------------ -FGRunway* runwayFromNasalArg( const FGAirport& apt, +FGRunwayRef runwayFromNasalArg( const FGAirport& apt, const nasal::CallContext& ctx, size_t index = 0 ) { if( index >= ctx.argc ) - return NULL; + return FGRunwayRef(); try { @@ -145,7 +145,7 @@ FGRunway* runwayFromNasalArg( const FGAirport& apt, { if( !apt.hasRunwayWithIdent(ident) ) // TODO warning/exception? - return NULL; + return FGRunwayRef(); return apt.getRunwayByIdent(ident); } @@ -154,7 +154,7 @@ FGRunway* runwayFromNasalArg( const FGAirport& apt, {} // TODO warn/error if no runway? - return NasalRunway::fromNasal(ctx.c, ctx.args[index]); + return ctx.from_nasal(ctx.args[index]); } //------------------------------------------------------------------------------ @@ -245,8 +245,8 @@ static bool extractGeod(nasal::CallContext& ctx, SGGeod& result) if( ctx.isGhost(0) ) { - FGPositioned* pos = - NasalPositioned::fromNasal(ctx.c, ctx.requireArg(0)); + FGPositionedRef pos = + ctx.from_nasal(ctx.requireArg(0)); if( pos ) { diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 090328e30..73c233372 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -487,7 +487,7 @@ static naRef f_makeTimer(naContext c, naRef me, int argc, naRef* args) } TimerObj* timerObj = new TimerObj(nasalSys, func, self, args[0].num); - return NasalTimerObj::create(c, timerObj); + return nasal::to_nasal(c, timerObj); } // setlistener(func, property, bool) extension function. Falls through to -- 2.39.5