7 # include <sys/time.h> // gettimeofday
12 #include <sys/types.h>
17 #include <simgear/nasal/nasal.h>
18 #include <simgear/props/props.hxx>
19 #include <simgear/math/sg_random.h>
20 #include <simgear/misc/sg_path.hxx>
21 #include <simgear/misc/interpolator.hxx>
22 #include <simgear/structure/commands.hxx>
23 #include <simgear/math/sg_geodesy.hxx>
25 #include <Main/globals.hxx>
26 #include <Main/fg_props.hxx>
28 #include "NasalSys.hxx"
30 static FGNasalSys* nasalSys = 0;
33 // Read and return file contents in a single buffer. Note use of
34 // stat() to get the file size. This is a win32 function, believe it
35 // or not. :) Note the REALLY IMPORTANT use of the "b" flag to fopen.
36 // Text mode brain damage will kill us if we're trying to do bytewise
38 static char* readfile(const char* file, int* lenOut)
41 if(stat(file, &data) != 0) return 0;
42 FILE* f = fopen(file, "rb");
44 char* buf = new char[data.st_size];
45 *lenOut = fread(buf, 1, data.st_size, f);
47 if(*lenOut != data.st_size) {
48 // Shouldn't happen, but warn anyway since it represents a
49 // platform bug and not a typical runtime error (missing file,
51 SG_LOG(SG_NASAL, SG_ALERT,
52 "ERROR in Nasal initialization: " <<
53 "short count returned from fread() of " << file <<
54 ". Check your C library!");
61 FGNasalSys::FGNasalSys()
67 _nextGCKey = 0; // Any value will do
69 _purgeListeners = false;
72 // Does a naCall() in a new context. Wrapped here to make lock
73 // tracking easier. Extension functions are called with the lock, but
74 // we have to release it before making a new naCall(). So rather than
75 // drop the lock in every extension function that might call back into
76 // Nasal, we keep a stack depth counter here and only unlock/lock
77 // around the naCall if it isn't the first one.
78 naRef FGNasalSys::call(naRef code, naRef locals)
80 naContext ctx = naNewContext();
81 if(_callCount) naModUnlock();
83 naRef result = naCall(ctx, code, 0, 0, naNil(), locals);
87 if(_callCount) naModLock();
92 FGNasalSys::~FGNasalSys()
95 map<int, FGNasalListener *>::iterator it, end = _listener.end();
96 for(it = _listener.begin(); it != end; ++it)
99 naFreeContext(_context);
103 bool FGNasalSys::parseAndRun(const char* sourceCode)
105 naRef code = parse("FGNasalSys::parseAndRun()", sourceCode,
113 FGNasalScript* FGNasalSys::parseScript(const char* src, const char* name)
115 FGNasalScript* script = new FGNasalScript();
116 script->_gcKey = -1; // important, if we delete it on a parse
117 script->_nas = this; // error, don't clobber a real handle!
121 sprintf(buf, "FGNasalScript@%p", (void *)script);
125 script->_code = parse(name, src, strlen(src));
126 if(naIsNil(script->_code)) {
131 script->_gcKey = gcSave(script->_code);
135 // Utility. Sets a named key in a hash by C string, rather than nasal
137 void FGNasalSys::hashset(naRef hash, const char* key, naRef val)
139 naRef s = naNewString(_context);
140 naStr_fromdata(s, (char*)key, strlen(key));
141 naHash_set(hash, s, val);
144 // The get/setprop functions accept a *list* of strings and walk
145 // through the property tree with them to find the appropriate node.
146 // This allows a Nasal object to hold onto a property path and use it
147 // like a node object, e.g. setprop(ObjRoot, "size-parsecs", 2.02). This
148 // is the utility function that walks the property tree.
149 // Future enhancement: support integer arguments to specify array
151 static SGPropertyNode* findnode(naContext c, naRef* vec, int len)
153 SGPropertyNode* p = globals->get_props();
155 for(int i=0; i<len; i++) {
157 if(!naIsString(a)) return 0;
158 p = p->getNode(naStr_data(a));
161 } catch (const string& err) {
162 naRuntimeError(c, (char *)err.c_str());
168 // getprop() extension function. Concatenates its string arguments as
169 // property names and returns the value of the specified property. Or
170 // nil if it doesn't exist.
171 static naRef f_getprop(naContext c, naRef me, int argc, naRef* args)
173 const SGPropertyNode* p = findnode(c, args, argc);
174 if(!p) return naNil();
176 switch(p->getType()) {
177 case SGPropertyNode::BOOL: case SGPropertyNode::INT:
178 case SGPropertyNode::LONG: case SGPropertyNode::FLOAT:
179 case SGPropertyNode::DOUBLE:
180 return naNum(p->getDoubleValue());
182 case SGPropertyNode::STRING:
183 case SGPropertyNode::UNSPECIFIED:
185 naRef nastr = naNewString(c);
186 const char* val = p->getStringValue();
187 naStr_fromdata(nastr, (char*)val, strlen(val));
190 case SGPropertyNode::ALIAS: // <--- FIXME, recurse?
196 // setprop() extension function. Concatenates its string arguments as
197 // property names and sets the value of the specified property to the
199 static naRef f_setprop(naContext c, naRef me, int argc, naRef* args)
202 char buf[BUFLEN + 1];
206 for(int i=0; i<argc-1; i++) {
207 naRef s = naStringValue(c, args[i]);
208 if(naIsNil(s)) return naNil();
209 strncpy(p, naStr_data(s), buflen);
211 buflen = BUFLEN - (p - buf);
212 if(i < (argc-2) && buflen > 0) {
218 SGPropertyNode* props = globals->get_props();
219 naRef val = args[argc-1];
221 if(naIsString(val)) props->setStringValue(buf, naStr_data(val));
223 naRef n = naNumValue(val);
225 naRuntimeError(c, "setprop() value is not string or number");
226 props->setDoubleValue(buf, n.num);
228 } catch (const string& err) {
229 naRuntimeError(c, (char *)err.c_str());
235 // print() extension function. Concatenates and prints its arguments
236 // to the FlightGear log. Uses the highest log level (SG_ALERT), to
237 // make sure it appears. Is there better way to do this?
238 static naRef f_print(naContext c, naRef me, int argc, naRef* args)
242 for(int i=0; i<n; i++) {
243 naRef s = naStringValue(c, args[i]);
244 if(naIsNil(s)) continue;
245 buf += naStr_data(s);
247 SG_LOG(SG_GENERAL, SG_ALERT, buf);
248 return naNum(buf.length());
251 // fgcommand() extension function. Executes a named command via the
252 // FlightGear command manager. Takes a single property node name as
254 static naRef f_fgcommand(naContext c, naRef me, int argc, naRef* args)
256 naRef cmd = argc > 0 ? args[0] : naNil();
257 naRef props = argc > 1 ? args[1] : naNil();
258 if(!naIsString(cmd) || (!naIsNil(props) && !naIsGhost(props)))
259 naRuntimeError(c, "bad arguments to fgcommand()");
260 SGPropertyNode_ptr tmp, *node;
262 node = (SGPropertyNode_ptr*)naGhost_ptr(props);
264 tmp = new SGPropertyNode();
267 return naNum(globals->get_commands()->execute(naStr_data(cmd), *node));
270 // settimer(func, dt, simtime) extension function. Falls through to
271 // FGNasalSys::setTimer(). See there for docs.
272 static naRef f_settimer(naContext c, naRef me, int argc, naRef* args)
274 nasalSys->setTimer(c, argc, args);
278 // setlistener(func, property, bool) extension function. Falls through to
279 // FGNasalSys::setListener(). See there for docs.
280 static naRef f_setlistener(naContext c, naRef me, int argc, naRef* args)
282 return nasalSys->setListener(c, argc, args);
285 // removelistener(int) extension function. Falls through to
286 // FGNasalSys::removeListener(). See there for docs.
287 static naRef f_removelistener(naContext c, naRef me, int argc, naRef* args)
289 return nasalSys->removeListener(c, argc, args);
292 // Returns a ghost handle to the argument to the currently executing
294 static naRef f_cmdarg(naContext c, naRef me, int argc, naRef* args)
296 return nasalSys->cmdArgGhost();
299 // Sets up a property interpolation. The first argument is either a
300 // ghost (SGPropertyNode_ptr*) or a string (global property path) to
301 // interpolate. The second argument is a vector of pairs of
302 // value/delta numbers.
303 static naRef f_interpolate(naContext c, naRef me, int argc, naRef* args)
305 SGPropertyNode* node;
306 naRef prop = argc > 0 ? args[0] : naNil();
307 if(naIsString(prop)) node = fgGetNode(naStr_data(prop), true);
308 else if(naIsGhost(prop)) node = *(SGPropertyNode_ptr*)naGhost_ptr(prop);
311 naRef curve = argc > 1 ? args[1] : naNil();
312 if(!naIsVector(curve)) return naNil();
313 int nPoints = naVec_size(curve) / 2;
314 double* values = new double[nPoints];
315 double* deltas = new double[nPoints];
316 for(int i=0; i<nPoints; i++) {
317 values[i] = naNumValue(naVec_get(curve, 2*i)).num;
318 deltas[i] = naNumValue(naVec_get(curve, 2*i+1)).num;
321 ((SGInterpolator*)globals->get_subsystem_mgr()
322 ->get_group(SGSubsystemMgr::INIT)->get_subsystem("interpolator"))
323 ->interpolate(node, nPoints, values, deltas);
328 // This is a better RNG than the one in the default Nasal distribution
329 // (which is based on the C library rand() implementation). It will
331 static naRef f_rand(naContext c, naRef me, int argc, naRef* args)
333 return naNum(sg_random());
336 static naRef f_srand(naContext c, naRef me, int argc, naRef* args)
342 // Return an array listing of all files in a directory
343 static naRef f_directory(naContext c, naRef me, int argc, naRef* args)
345 if(argc != 1 || !naIsString(args[0]))
346 naRuntimeError(c, "bad arguments to directory()");
347 naRef ldir = args[0];
348 ulDir* dir = ulOpenDir(naStr_data(args[0]));
349 if(!dir) return naNil();
350 naRef result = naNewVector(c);
352 while((dent = ulReadDir(dir)))
353 naVec_append(result, naStr_fromdata(naNewString(c), dent->d_name,
354 strlen(dent->d_name)));
359 // Return UNIX epoch time in seconds.
360 static naRef f_systime(naContext c, naRef me, int argc, naRef* args)
364 GetSystemTimeAsFileTime(&ft);
365 double t = (4294967296.0 * ft.dwHighDateTime + ft.dwLowDateTime);
366 // Converts from 100ns units in 1601 epoch to unix epoch in sec
367 return naNum((t * 1e-7) - 11644473600.0);
371 do { t = time(0); gettimeofday(&td, 0); } while(t != time(0));
372 return naNum(t + 1e-6 * td.tv_usec);
377 // Convert a cartesian point to a geodetic lat/lon/altitude.
378 static naRef f_carttogeod(naContext c, naRef me, int argc, naRef* args)
380 double lat, lon, alt, xyz[3];
381 static const float RAD2DEG = 1./0.0174532925199;
382 if(argc != 3) naRuntimeError(c, "carttogeod() expects 3 arguments");
383 for(int i=0; i<3; i++)
384 xyz[i] = naNumValue(args[i]).num;
385 sgCartToGeod(xyz, &lat, &lon, &alt);
388 naRef vec = naNewVector(c);
389 naVec_append(vec, naNum(lat));
390 naVec_append(vec, naNum(lon));
391 naVec_append(vec, naNum(alt));
395 // Convert a cartesian point to a geodetic lat/lon/altitude.
396 static naRef f_geodtocart(naContext c, naRef me, int argc, naRef* args)
398 static const float DEG2RAD = 0.0174532925199;
399 if(argc != 3) naRuntimeError(c, "geodtocart() expects 3 arguments");
400 double lat = naNumValue(args[0]).num * DEG2RAD;
401 double lon = naNumValue(args[1]).num * DEG2RAD;
402 double alt = naNumValue(args[2]).num * DEG2RAD;
404 sgGeodToCart(lat, lon, alt, xyz);
405 naRef vec = naNewVector(c);
406 naVec_append(vec, naNum(xyz[0]));
407 naVec_append(vec, naNum(xyz[1]));
408 naVec_append(vec, naNum(xyz[2]));
412 // Table of extension functions. Terminate with zeros.
413 static struct { char* name; naCFunction func; } funcs[] = {
414 { "getprop", f_getprop },
415 { "setprop", f_setprop },
416 { "print", f_print },
417 { "_fgcommand", f_fgcommand },
418 { "settimer", f_settimer },
419 { "_setlistener", f_setlistener },
420 { "removelistener", f_removelistener },
421 { "_cmdarg", f_cmdarg },
422 { "_interpolate", f_interpolate },
424 { "srand", f_srand },
425 { "directory", f_directory },
426 { "systime", f_systime },
427 { "carttogeod", f_carttogeod },
428 { "geodtocart", f_geodtocart },
432 naRef FGNasalSys::cmdArgGhost()
434 return propNodeGhost(_cmdArg);
437 void FGNasalSys::init()
441 _context = naNewContext();
443 // Start with globals. Add it to itself as a recursive
444 // sub-reference under the name "globals". This gives client-code
445 // write access to the namespace if someone wants to do something
447 _globals = naInit_std(_context);
448 naSave(_context, _globals);
449 hashset(_globals, "globals", _globals);
451 hashset(_globals, "math", naInit_math(_context));
452 hashset(_globals, "bits", naInit_bits(_context));
453 hashset(_globals, "io", naInit_io(_context));
454 hashset(_globals, "thread", naInit_thread(_context));
455 hashset(_globals, "utf8", naInit_utf8(_context));
457 // Add our custom extension functions:
458 for(i=0; funcs[i].name; i++)
459 hashset(_globals, funcs[i].name,
460 naNewFunc(_context, naNewCCode(_context, funcs[i].func)));
462 // And our SGPropertyNode wrapper
463 hashset(_globals, "props", genPropsModule());
465 // Make a "__gcsave" hash to hold the naRef objects which get
466 // passed to handles outside the interpreter (to protect them from
467 // begin garbage-collected).
468 _gcHash = naNewHash(_context);
469 hashset(_globals, "__gcsave", _gcHash);
471 // Now load the various source files in the Nasal directory
472 SGPath p(globals->get_fg_root());
475 ulDir* dir = ulOpenDir(p.c_str());
476 while(dir && (dent = ulReadDir(dir)) != 0) {
478 fullpath.append(dent->d_name);
479 SGPath file(dent->d_name);
480 if(file.extension() != "nas") continue;
481 loadModule(fullpath, file.base().c_str());
485 // set signal and remove node to avoid restoring at reinit
486 const char *s = "nasal-dir-initialized";
487 SGPropertyNode *signal = fgGetNode("/sim/signals", true);
488 signal->setBoolValue(s, true);
489 signal->removeChildren(s);
491 // Pull scripts out of the property tree, too
492 loadPropertyScripts();
495 void FGNasalSys::update(double)
497 if(_purgeListeners) {
498 _purgeListeners = false;
499 map<int, FGNasalListener *>::iterator it;
500 for(it = _listener.begin(); it != _listener.end();) {
501 FGNasalListener *nl = it->second;
503 _listener.erase(it++);
512 // Loads the scripts found under /nasal in the global tree
513 void FGNasalSys::loadPropertyScripts()
515 SGPropertyNode* nasal = globals->get_props()->getNode("nasal");
518 for(int i=0; i<nasal->nChildren(); i++) {
519 SGPropertyNode* n = nasal->getChild(i);
521 const char* module = n->getName();
522 if(n->hasChild("module"))
523 module = n->getStringValue("module");
525 // allow multiple files to be specified within in a single
529 bool file_specified = false;
530 while ( (fn = n->getChild("file", j)) != NULL ) {
531 file_specified = true;
532 const char* file = fn->getStringValue();
533 SGPath p(globals->get_fg_root());
535 loadModule(p, module);
539 // Old code which only allowed a single file to be specified per module
541 const char* file = n->getStringValue("file");
542 if(!n->hasChild("file")) file = 0; // Hrm...
544 SGPath p(globals->get_fg_root());
546 loadModule(p, module);
550 const char* src = n->getStringValue("script");
551 if(!n->hasChild("script")) src = 0; // Hrm...
553 createModule(module, n->getPath(), src, strlen(src));
555 if(!file_specified && !src)
556 SG_LOG(SG_NASAL, SG_ALERT, "Nasal error: " <<
557 "no <file> or <script> defined in " <<
558 "/nasal/" << module);
562 // Logs a runtime error, with stack trace, to the FlightGear log stream
563 void FGNasalSys::logError(naContext context)
565 SG_LOG(SG_NASAL, SG_ALERT,
566 "Nasal runtime error: " << naGetError(context));
567 SG_LOG(SG_NASAL, SG_ALERT,
568 " at " << naStr_data(naGetSourceFile(context, 0)) <<
569 ", line " << naGetLine(context, 0));
570 for(int i=1; i<naStackDepth(context); i++)
571 SG_LOG(SG_NASAL, SG_ALERT,
572 " called from: " << naStr_data(naGetSourceFile(context, i)) <<
573 ", line " << naGetLine(context, i));
576 // Reads a script file, executes it, and places the resulting
577 // namespace into the global namespace under the specified module
579 void FGNasalSys::loadModule(SGPath file, const char* module)
582 char* buf = readfile(file.c_str(), &len);
584 SG_LOG(SG_NASAL, SG_ALERT,
585 "Nasal error: could not read script file " << file.c_str()
586 << " into module " << module);
590 createModule(module, file.c_str(), buf, len);
594 // Parse and run. Save the local variables namespace, as it will
595 // become a sub-object of globals. The optional "arg" argument can be
596 // used to pass an associated property node to the module, which can then
597 // be accessed via cmdarg(). (This is, for example, used by XML dialogs.)
598 void FGNasalSys::createModule(const char* moduleName, const char* fileName,
599 const char* src, int len, const SGPropertyNode* arg)
601 naRef code = parse(fileName, src, len);
605 // See if we already have a module hash to use. This allows the
606 // user to, for example, add functions to the built-in math
607 // module. Make a new one if necessary.
609 naRef modname = naNewString(_context);
610 naStr_fromdata(modname, (char*)moduleName, strlen(moduleName));
611 if(!naHash_get(_globals, modname, &locals))
612 locals = naNewHash(_context);
614 _cmdArg = (SGPropertyNode*)arg;
617 hashset(_globals, moduleName, locals);
620 void FGNasalSys::deleteModule(const char* moduleName)
622 naRef modname = naNewString(_context);
623 naStr_fromdata(modname, (char*)moduleName, strlen(moduleName));
624 naHash_delete(_globals, modname);
627 naRef FGNasalSys::parse(const char* filename, const char* buf, int len)
630 naRef srcfile = naNewString(_context);
631 naStr_fromdata(srcfile, (char*)filename, strlen(filename));
632 naRef code = naParseCode(_context, srcfile, 1, (char*)buf, len, &errLine);
634 SG_LOG(SG_NASAL, SG_ALERT,
635 "Nasal parse error: " << naGetError(_context) <<
636 " in "<< filename <<", line " << errLine);
640 // Bind to the global namespace before returning
641 return naBindFunction(_context, code, _globals);
644 bool FGNasalSys::handleCommand(const SGPropertyNode* arg)
646 const char* nasal = arg->getStringValue("script");
647 const char* moduleName = arg->getStringValue("module");
648 naRef code = parse(arg->getPath(true), nasal, strlen(nasal));
649 if(naIsNil(code)) return false;
651 // Commands can be run "in" a module. Make sure that module
652 // exists, and set it up as the local variables hash for the
654 naRef locals = naNil();
656 naRef modname = naNewString(_context);
657 naStr_fromdata(modname, (char*)moduleName, strlen(moduleName));
658 if(!naHash_get(_globals, modname, &locals)) {
659 locals = naNewHash(_context);
660 naHash_set(_globals, modname, locals);
664 // Cache this command's argument for inspection via cmdarg(). For
665 // performance reasons, we won't bother with it if the invoked
666 // code doesn't need it.
667 _cmdArg = (SGPropertyNode*)arg;
673 // settimer(func, dt, simtime) extension function. The first argument
674 // is a Nasal function to call, the second is a delta time (from now),
675 // in seconds. The third, if present, is a boolean value indicating
676 // that "real world" time (rather than simulator time) is to be used.
678 // Implementation note: the FGTimer objects don't live inside the
679 // garbage collector, so the Nasal handler functions have to be
680 // "saved" somehow lest they be inadvertently cleaned. In this case,
681 // they are inserted into a globals.__gcsave hash and removed on
683 void FGNasalSys::setTimer(naContext c, int argc, naRef* args)
685 // Extract the handler, delta, and simtime arguments:
686 naRef handler = argc > 0 ? args[0] : naNil();
687 if(!(naIsCode(handler) || naIsCCode(handler) || naIsFunc(handler))) {
688 naRuntimeError(c, "settimer() with invalid function argument");
692 naRef delta = argc > 1 ? args[1] : naNil();
694 naRuntimeError(c, "settimer() with invalid time argument");
698 bool simtime = (argc > 2 && naTrue(args[2])) ? false : true;
700 // Generate and register a C++ timer handler
701 NasalTimer* t = new NasalTimer;
702 t->handler = handler;
703 t->gcKey = gcSave(handler);
706 globals->get_event_mgr()->addEvent("NasalTimer",
707 t, &NasalTimer::timerExpired,
711 void FGNasalSys::handleTimer(NasalTimer* t)
713 call(t->handler, naNil());
717 int FGNasalSys::gcSave(naRef r)
719 int key = _nextGCKey++;
720 naHash_set(_gcHash, naNum(key), r);
724 void FGNasalSys::gcRelease(int key)
726 naHash_delete(_gcHash, naNum(key));
729 void FGNasalSys::NasalTimer::timerExpired()
731 nasal->handleTimer(this);
735 int FGNasalSys::_listenerId = 0;
737 // setlistener(property, func, bool) extension function. The first argument
738 // is either a ghost (SGPropertyNode_ptr*) or a string (global property
739 // path), the second is a Nasal function, the optional third one a bool.
740 // If the bool is true, then the listener is executed initially. The
741 // setlistener() function returns a unique id number, that can be used
742 // as argument to the removelistener() function.
743 naRef FGNasalSys::setListener(naContext c, int argc, naRef* args)
745 SGPropertyNode_ptr node;
746 naRef prop = argc > 0 ? args[0] : naNil();
747 if(naIsString(prop)) node = fgGetNode(naStr_data(prop), true);
748 else if(naIsGhost(prop)) node = *(SGPropertyNode_ptr*)naGhost_ptr(prop);
750 naRuntimeError(c, "setlistener() with invalid property argument");
755 SG_LOG(SG_NASAL, SG_DEBUG, "Attaching listener to tied property " <<
758 naRef handler = argc > 1 ? args[1] : naNil();
759 if(!(naIsCode(handler) || naIsCCode(handler) || naIsFunc(handler))) {
760 naRuntimeError(c, "setlistener() with invalid function argument");
764 bool initial = argc > 2 && naTrue(args[2]);
766 FGNasalListener *nl = new FGNasalListener(node, handler, this,
767 gcSave(handler), _listenerId);
768 node->addChangeListener(nl, initial);
770 _listener[_listenerId] = nl;
771 return naNum(_listenerId++);
774 // removelistener(int) extension function. The argument is the id of
775 // a listener as returned by the setlistener() function.
776 naRef FGNasalSys::removeListener(naContext c, int argc, naRef* args)
778 naRef id = argc > 0 ? args[0] : naNil();
779 map<int, FGNasalListener *>::iterator it = _listener.find(int(id.num));
781 if(!naIsNum(id) || it == _listener.end() || it->second->_dead) {
782 naRuntimeError(c, "removelistener() with invalid listener id");
786 FGNasalListener *nl = it->second;
789 _purgeListeners = true;
795 return naNum(_listener.size());
800 // FGNasalListener class.
802 FGNasalListener::FGNasalListener(SGPropertyNode_ptr node, naRef handler,
803 FGNasalSys* nasal, int key, int id) :
814 FGNasalListener::~FGNasalListener()
816 _node->removeChangeListener(this);
817 _nas->gcRelease(_gcKey);
820 void FGNasalListener::valueChanged(SGPropertyNode* node)
822 // drop recursive listener calls
826 SG_LOG(SG_NASAL, SG_DEBUG, "trigger listener #" << _id);
828 _nas->_cmdArg = node;
829 _nas->call(_handler, naNil());
836 // FGNasalModelData class. If sgLoad3DModel() is called with a pointer to
837 // such a class, then it lets modelLoaded() run the <load> script, and the
838 // destructor the <unload> script. The latter happens when the model branch
839 // is removed from the scene graph.
841 void FGNasalModelData::modelLoaded(const string& path, SGPropertyNode *prop,
844 SGPropertyNode *n = prop->getNode("nasal"), *load;
848 load = n->getNode("load");
849 _unload = n->getNode("unload");
850 if(!load && !_unload)
854 const char *s = load ? load->getStringValue() : "";
855 nasalSys->createModule(_module.c_str(), _module.c_str(), s, strlen(s), _props);
858 FGNasalModelData::~FGNasalModelData()
864 SG_LOG(SG_NASAL, SG_ALERT, "Trying to run an <unload> script "
865 "without Nasal subsystem present.");
870 const char *s = _unload->getStringValue();
871 nasalSys->createModule(_module.c_str(), _module.c_str(), s, strlen(s), _props);
873 nasalSys->deleteModule(_module.c_str());