diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index c25c3779c..bcc797e12 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -280,6 +281,24 @@ static naRef f_removelistener(naContext c, naRef me, int argc, naRef* args) return nasal->removeListener(c, argc, args); } +// condition(property) extension function. Evaluates standard +// (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 // command 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 }, { "_setlistener", f_setlistener }, { "removelistener", f_removelistener }, + { "_condition", f_condition }, { "_cmdarg", f_cmdarg }, { "_interpolate", f_interpolate }, { "rand", f_rand },