1
0
Fork 0

Scripting: expose flight history as aircraft.history()

var hist = aircraft.history();
 debug.dump(hist.pathForHistory(50));
This commit is contained in:
Thomas Geymayer 2014-05-10 10:52:16 +02:00
parent bd29974683
commit 0fc2d57211
5 changed files with 85 additions and 3 deletions

View 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

View file

@ -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);
}

View file

@ -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

View 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);

View 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