New Nasal command _condition(p) where p is a property node containing
a condition as described in $FG_ROOT/Docs/README.condition. Returns 1 if condition is true, 0 if false, and nil on error.
This commit is contained in:
parent
8617b0a82a
commit
cc30d4d80e
1 changed files with 20 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include <simgear/nasal/nasal.h>
|
#include <simgear/nasal/nasal.h>
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
|
#include <simgear/props/condition.hxx>
|
||||||
#include <simgear/math/sg_random.h>
|
#include <simgear/math/sg_random.h>
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
#include <simgear/misc/interpolator.hxx>
|
#include <simgear/misc/interpolator.hxx>
|
||||||
|
@ -280,6 +281,24 @@ static naRef f_removelistener(naContext c, naRef me, int argc, naRef* args)
|
||||||
return nasal->removeListener(c, argc, args);
|
return nasal->removeListener(c, argc, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// condition(property) extension function. Evaluates standard <condition>
|
||||||
|
// (see $FG_ROOT/Docs/README.condition) and returns state.
|
||||||
|
static naRef f_condition(naContext c, naRef me, int argc, naRef* args)
|
||||||
|
{
|
||||||
|
SGPropertyNode* node;
|
||||||
|
naRef prop = argc > 0 ? args[0] : naNil();
|
||||||
|
if(naIsString(prop)) node = fgGetNode(naStr_data(prop), true);
|
||||||
|
else if(naIsGhost(prop)) node = *(SGPropertyNode_ptr*)naGhost_ptr(prop);
|
||||||
|
else {
|
||||||
|
naRuntimeError(c, "condition() with invalid property");
|
||||||
|
return naNil();
|
||||||
|
}
|
||||||
|
SGCondition *cond = sgReadCondition(globals->get_props(), node);
|
||||||
|
bool result = cond->test();
|
||||||
|
delete cond;
|
||||||
|
return naNum(result == true ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
// Returns a ghost handle to the argument to the currently executing
|
// Returns a ghost handle to the argument to the currently executing
|
||||||
// command
|
// command
|
||||||
static naRef f_cmdarg(naContext c, naRef me, int argc, naRef* args)
|
static naRef f_cmdarg(naContext c, naRef me, int argc, naRef* args)
|
||||||
|
@ -356,6 +375,7 @@ static struct { char* name; naCFunction func; } funcs[] = {
|
||||||
{ "settimer", f_settimer },
|
{ "settimer", f_settimer },
|
||||||
{ "_setlistener", f_setlistener },
|
{ "_setlistener", f_setlistener },
|
||||||
{ "removelistener", f_removelistener },
|
{ "removelistener", f_removelistener },
|
||||||
|
{ "_condition", f_condition },
|
||||||
{ "_cmdarg", f_cmdarg },
|
{ "_cmdarg", f_cmdarg },
|
||||||
{ "_interpolate", f_interpolate },
|
{ "_interpolate", f_interpolate },
|
||||||
{ "rand", f_rand },
|
{ "rand", f_rand },
|
||||||
|
|
Loading…
Reference in a new issue