]> git.mxchange.org Git - flightgear.git/commitdiff
Allow the second (property node) argument to fgcommand() to be nil or
authorandy <andy>
Thu, 7 Jun 2007 16:17:48 +0000 (16:17 +0000)
committerandy <andy>
Thu, 7 Jun 2007 16:17:48 +0000 (16:17 +0000)
missing, for sanity.  Note that this will pass the resulting NULL
pointer through into the underlying SGCommand handlers, some of which
may be unprepared for it.  So basically this is now yet another way
you can use Nasal to exercise bugs and hose your sim; no biggie.

src/Scripting/NasalSys.cxx

index 133d8f7407c973f36b916da949589f9284a37ee1..7fb471b49fc55a4008d614ff32c24b4bb0714441 100644 (file)
@@ -252,10 +252,13 @@ static naRef f_print(naContext c, naRef me, int argc, naRef* args)
 // an argument.
 static naRef f_fgcommand(naContext c, naRef me, int argc, naRef* args)
 {
-    if(argc < 2 || !naIsString(args[0]) || !naIsGhost(args[1]))
+    naRef cmd = argc > 0 ? args[0] : naNil();
+    naRef props = argc > 1 ? args[1] : naNil();
+    if(!naIsString(cmd) || (!naIsNil(props) && !naIsGhost(props)))
         naRuntimeError(c, "bad arguments to fgcommand()");
-    naRef cmd = args[0], props = args[1];
-    SGPropertyNode_ptr* node = (SGPropertyNode_ptr*)naGhost_ptr(props);
+    SGPropertyNode_ptr* node = NULL;
+    if(!naIsNil(props))
+        node = (SGPropertyNode_ptr*)naGhost_ptr(props);
     return naNum(globals->get_commands()->execute(naStr_data(cmd), *node));
 }