From: Thomas Geymayer Date: Sat, 10 May 2014 08:52:16 +0000 (+0200) Subject: Scripting: expose flight history as aircraft.history() X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0fc2d57211e57ea2f166d1f08dd3b9a765404f37;p=flightgear.git Scripting: expose flight history as aircraft.history() var hist = aircraft.history(); debug.dump(hist.pathForHistory(50)); --- diff --git a/src/Scripting/CMakeLists.txt b/src/Scripting/CMakeLists.txt index 413a137a7..1a40daa70 100644 --- a/src/Scripting/CMakeLists.txt +++ b/src/Scripting/CMakeLists.txt @@ -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 index 000000000..eca49b765 --- /dev/null +++ b/src/Scripting/NasalAircraft.cxx @@ -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 +#include
+ +#include +#include + +//------------------------------------------------------------------------------ +static naRef f_getHistory(const nasal::CallContext& ctx) +{ + FGFlightHistory* history = + static_cast(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 >::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 index 000000000..fd8b3f985 --- /dev/null +++ b/src/Scripting/NasalAircraft.hxx @@ -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 + +void initNasalAircraft(naRef globals, naContext c); + +#endif // SCRIPTING_NASAL_AIRCRAFT_HXX + diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 6e8c4ef05..090328e30 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -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); diff --git a/src/Scripting/NasalSys.hxx b/src/Scripting/NasalSys.hxx index 44f30b5bd..bbb2ace90 100644 --- a/src/Scripting/NasalSys.hxx +++ b/src/Scripting/NasalSys.hxx @@ -1,13 +1,15 @@ #ifndef __NASALSYS_HXX #define __NASALSYS_HXX -#include -#include +#include // keep before any cppbind include to enable + // SGVec2 conversion. #include +#include #include #include -#include #include +#include +#include // Required only for MSVC #ifdef _MSC_VER