]> git.mxchange.org Git - flightgear.git/commitdiff
Updates for simgear nasal::Ghost changes.
authorThomas Geymayer <tomgey@gmail.com>
Tue, 3 Jun 2014 00:23:17 +0000 (02:23 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Tue, 3 Jun 2014 17:00:25 +0000 (19:00 +0200)
src/GUI/FileDialog.cxx
src/Scripting/NasalCanvas.cxx
src/Scripting/NasalPositioned_cppbind.cxx
src/Scripting/NasalSys.cxx

index f7dfcc116cef8c1691407087bee87847ac8c2d68..e8fdc3724804e476fc57297fa1d82f6afcd507e9 100644 (file)
@@ -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)
index b3dae9671c938dbfa9c2a85d5f1d3c956a87ac16..4da6b5a23b00c34eb21cc51250b3131931268d18 100644 (file)
@@ -73,7 +73,7 @@ typedef nasal::Ghost<sc::TextPtr> NasalText;
 typedef nasal::Ghost<sc::LayoutItemRef> NasalLayoutItem;
 typedef nasal::Ghost<sc::LayoutRef> NasalLayout;
 
-typedef nasal::Ghost<sc::WindowWeakPtr> NasalWindow;
+typedef nasal::Ghost<sc::WindowPtr> 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<sc::CanvasPtr>(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<sc::WindowWeakPtr>
   (
     ctx.c,
     requireGUIMgr(ctx.c).createWindow( ctx.getArg<std::string>(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<std::string>(0) )
-  );
+  return ctx.to_nasal( canvas.createGroup(ctx.getArg<std::string>(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<std::string>(0),
-                       ctx.getArg<std::string>(1) )
-  );
+  return ctx.to_nasal( group.createChild( ctx.requireArg<std::string>(0),
+                                          ctx.getArg<std::string>(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<SGPropertyNode*>(0) )
-  );
-}
-
-naRef f_groupGetElementById(sc::Group& group, const nasal::CallContext& ctx)
-{
-  return NasalElement::create
-  (
-    ctx.c,
-    group.getElementById( ctx.requireArg<std::string>(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<simgear::StringMap>(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<class Type, class Base>
 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<bool (sc::Canvas::*)( const std::string&,
+                                               const sc::EventListener& )>
+             (&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<NasalElement>()
     .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<NasalElement>()
     .method("getNearestCursor", &sc::Text::getNearestCursor);
index 9f3a1968cf79c1d6bd87e59257094da3504f9457..7ef63d02c5f7aea29c6241d094cb131c87e8e57c 100644 (file)
@@ -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<FGRunwayRef>(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<naRef>(0));
+    FGPositionedRef pos =
+      ctx.from_nasal<FGPositionedRef>(ctx.requireArg<naRef>(0));
 
     if( pos )
     {
index 090328e30328ff14e63b18af8cbb67600160afa2..73c233372f56a4d833ad167c697eec9f67c2332f 100644 (file)
@@ -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