]> git.mxchange.org Git - flightgear.git/commitdiff
Scripting: expose flight history as aircraft.history()
authorThomas Geymayer <tomgey@gmail.com>
Sat, 10 May 2014 08:52:16 +0000 (10:52 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Sat, 10 May 2014 08:56:09 +0000 (10:56 +0200)
 var hist = aircraft.history();
 debug.dump(hist.pathForHistory(50));

src/Scripting/CMakeLists.txt
src/Scripting/NasalAircraft.cxx [new file with mode: 0644]
src/Scripting/NasalAircraft.hxx [new file with mode: 0644]
src/Scripting/NasalSys.cxx
src/Scripting/NasalSys.hxx

index 413a137a759c411e9ee2df2d7cc0d26a40541e26..1a40daa70ab7f585f0bf0ae0a30a9d79f8e1d955 100644 (file)
@@ -3,6 +3,7 @@ include(FlightGearComponent)
 set(SOURCES
   NasalSys.cxx
   nasal-props.cxx
+  NasalAircraft.cxx
   NasalPositioned.cxx
   NasalPositioned_cppbind.cxx
   NasalCanvas.cxx
@@ -17,6 +18,7 @@ set(SOURCES
 set(HEADERS
   NasalSys.hxx
   NasalSys_private.hxx
+  NasalAircraft.hxx
   NasalPositioned.hxx
   NasalCanvas.hxx
   NasalClipboard.hxx
diff --git a/src/Scripting/NasalAircraft.cxx b/src/Scripting/NasalAircraft.cxx
new file mode 100644 (file)
index 0000000..eca49b7
--- /dev/null
@@ -0,0 +1,49 @@
+// Expose aircraft related data to Nasal
+//
+// Copyright (C) 2014 Thomas Geymayer
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "NasalAircraft.hxx"
+#include <Aircraft/FlightHistory.hxx>
+#include <Main/globals.hxx>
+
+#include <simgear/nasal/cppbind/NasalHash.hxx>
+#include <simgear/nasal/cppbind/Ghost.hxx>
+
+//------------------------------------------------------------------------------
+static naRef f_getHistory(const nasal::CallContext& ctx)
+{
+  FGFlightHistory* history =
+    static_cast<FGFlightHistory*>(globals->get_subsystem("history"));
+  if( !history )
+    naRuntimeError(ctx.c, "Failed to get 'history' subsystem");
+
+  return ctx.to_nasal(history);
+}
+
+//------------------------------------------------------------------------------
+void initNasalAircraft(naRef globals, naContext c)
+{
+  nasal::Ghost<SGSharedPtr<FGFlightHistory> >::init("FGFlightHistory")
+    .method("pathForHistory", &FGFlightHistory::pathForHistory);
+
+  nasal::Hash aircraft_module = nasal::Hash(globals, c).createHash("aircraft");
+  aircraft_module.set("history", &f_getHistory);
+}
diff --git a/src/Scripting/NasalAircraft.hxx b/src/Scripting/NasalAircraft.hxx
new file mode 100644 (file)
index 0000000..fd8b3f9
--- /dev/null
@@ -0,0 +1,27 @@
+//@file Expose aircraft related data to Nasal
+//
+// Copyright (C) 2014 Thomas Geymayer
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+#ifndef SCRIPTING_NASAL_AIRCRAFT_HXX
+#define SCRIPTING_NASAL_AIRCRAFT_HXX
+
+#include <simgear/nasal/nasal.h>
+
+void initNasalAircraft(naRef globals, naContext c);
+
+#endif // SCRIPTING_NASAL_AIRCRAFT_HXX
+
index 6e8c4ef05ccd8c36ab23a9535e5542a8afbf4735..090328e30328ff14e63b18af8cbb67600160afa2 100644 (file)
@@ -36,6 +36,7 @@
 #include "NasalSGPath.hxx"
 #include "NasalSys.hxx"
 #include "NasalSys_private.hxx"
+#include "NasalAircraft.hxx"
 #include "NasalModelData.hxx"
 #include "NasalPositioned.hxx"
 #include "NasalCanvas.hxx"
@@ -786,6 +787,7 @@ void FGNasalSys::init()
 
     initNasalPositioned(_globals, _context);
     initNasalPositioned_cppbind(_globals, _context);
+    initNasalAircraft(_globals, _context);
     NasalClipboard::init(this);
     initNasalCanvas(_globals, _context);
     initNasalCondition(_globals, _context);
index 44f30b5bdda05ed075db5c661bb021dfbea6b853..bbb2ace909f56497574933f3a6ab0347a94dc883 100644 (file)
@@ -1,13 +1,15 @@
 #ifndef __NASALSYS_HXX
 #define __NASALSYS_HXX
 
-#include <simgear/misc/sg_path.hxx>
-#include <simgear/structure/subsystem_mgr.hxx>
+#include <simgear/math/SGMath.hxx> // keep before any cppbind include to enable
+                                   // SGVec2<T> conversion.
 #include <simgear/misc/sg_dir.hxx>
+#include <simgear/misc/sg_path.hxx>
 #include <simgear/nasal/cppbind/NasalHash.hxx>
 #include <simgear/nasal/nasal.h>
-#include <simgear/threads/SGQueue.hxx>
 #include <simgear/props/props.hxx>
+#include <simgear/structure/subsystem_mgr.hxx>
+#include <simgear/threads/SGQueue.hxx>
 
 // Required only for MSVC
 #ifdef _MSC_VER