2012-08-19 21:13:31 +01:00
|
|
|
// NasalCondition -- expose SGCondition to Nasal
|
|
|
|
//
|
|
|
|
// Written by James Turner, started 2012.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2012 James Turner
|
|
|
|
//
|
|
|
|
// 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 "NasalCondition.hxx"
|
|
|
|
#include "NasalSys.hxx"
|
|
|
|
#include <Main/globals.hxx>
|
|
|
|
|
2014-06-22 15:37:48 +02:00
|
|
|
#include <simgear/nasal/cppbind/Ghost.hxx>
|
|
|
|
#include <simgear/nasal/cppbind/NasalHash.hxx>
|
2012-08-19 21:13:31 +01:00
|
|
|
#include <simgear/props/condition.hxx>
|
|
|
|
|
2014-06-22 15:37:48 +02:00
|
|
|
typedef nasal::Ghost<SGConditionRef> NasalCondition;
|
2012-08-19 21:13:31 +01:00
|
|
|
|
2014-06-22 15:37:48 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static naRef f_createCondition(naContext c, naRef me, int argc, naRef* args)
|
2012-08-19 21:13:31 +01:00
|
|
|
{
|
2014-06-22 15:37:48 +02:00
|
|
|
SGPropertyNode* node = argc > 0
|
|
|
|
? ghostToPropNode(args[0])
|
|
|
|
: NULL;
|
|
|
|
SGPropertyNode* root = argc > 1
|
|
|
|
? ghostToPropNode(args[1])
|
|
|
|
: globals->get_props();
|
2012-08-19 21:13:31 +01:00
|
|
|
|
2014-06-22 15:37:48 +02:00
|
|
|
if( !node || !root )
|
|
|
|
naRuntimeError(c, "createCondition: invalid argument(s)");
|
2012-08-19 21:13:31 +01:00
|
|
|
|
2014-06-22 15:37:48 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return nasal::to_nasal(c, sgReadCondition(root, node));
|
2012-08-19 21:13:31 +01:00
|
|
|
}
|
2014-06-22 15:37:48 +02:00
|
|
|
catch(std::exception& ex)
|
|
|
|
{
|
|
|
|
naRuntimeError(c, "createCondition: %s", ex.what());
|
2012-08-19 21:13:31 +01:00
|
|
|
}
|
2014-06-23 00:42:17 +02:00
|
|
|
|
|
|
|
return naNil();
|
2012-08-19 21:13:31 +01:00
|
|
|
}
|
|
|
|
|
2014-06-22 15:37:48 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
naRef initNasalCondition(naRef globals, naContext c)
|
2012-08-19 21:13:31 +01:00
|
|
|
{
|
2014-06-22 15:37:48 +02:00
|
|
|
nasal::Ghost<SGConditionRef>::init("Condition")
|
|
|
|
.method("test", &SGCondition::test);
|
2012-08-19 21:13:31 +01:00
|
|
|
|
2014-06-22 15:37:48 +02:00
|
|
|
nasal::Hash(globals, c).set("_createCondition", f_createCondition);
|
2012-08-19 21:13:31 +01:00
|
|
|
|
|
|
|
return naNil();
|
|
|
|
}
|