]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scripting/NasalSys.cxx
Bugfix - untie property.
[flightgear.git] / src / Scripting / NasalSys.cxx
index c10c4d05860aa159b5a605f5c9abed8fb981da1f..ae5d9c0af73ef1c579050af11c47f53ac552942a 100644 (file)
@@ -212,6 +212,7 @@ static naRef f_setprop(naContext c, naRef me, int argc, naRef* args)
     buf[BUFLEN] = 0;
     char* p = buf;
     int buflen = BUFLEN;
+    if(argc < 2) naRuntimeError(c, "setprop() expects at least 2 arguments");
     for(int i=0; i<argc-1; i++) {
         naRef s = naStringValue(c, args[i]);
         if(naIsNil(s)) return naNil();
@@ -374,6 +375,19 @@ static naRef f_directory(naContext c, naRef me, int argc, naRef* args)
     return result;
 }
 
+/**
+ * Given a data path, resolve it in FG_ROOT or an FG_AIRCRFT directory
+ */
+static naRef f_resolveDataPath(naContext c, naRef me, int argc, naRef* args)
+{
+    if(argc != 1 || !naIsString(args[0]))
+        naRuntimeError(c, "bad arguments to resolveDataPath()");
+
+    SGPath p = globals->resolve_maybe_aircraft_path(naStr_data(args[0]));
+    const char* pdata = p.c_str();
+    return naStr_fromdata(naNewString(c), const_cast<char*>(pdata), strlen(pdata));
+}
+
 // Parse XML file.
 //     parsexml(<path> [, <start-tag> [, <end-tag> [, <data> [, <pi>]]]]);
 //
@@ -415,7 +429,7 @@ static naRef f_parsexml(naContext c, naRef me, int argc, naRef* args)
 // Return UNIX epoch time in seconds.
 static naRef f_systime(naContext c, naRef me, int argc, naRef* args)
 {
-#ifdef WIN32
+#ifdef _WIN32
     FILETIME ft;
     GetSystemTimeAsFileTime(&ft);
     double t = (4294967296.0 * ft.dwHighDateTime + ft.dwLowDateTime);
@@ -596,7 +610,7 @@ static naRef f_airportinfo(naContext c, naRef me, int argc, naRef* args)
         HASHSET("stopway", 7, naNum(rwy->stopwayM()));
         
         if (rwy->ILS()) {
-          HASHSET("ils-frequency-mhz", 3, naNum(rwy->ILS()->get_freq() / 100.0));
+          HASHSET("ils_frequency_mhz", 17, naNum(rwy->ILS()->get_freq() / 100.0));
         }
         
 #undef HASHSET
@@ -635,6 +649,7 @@ static struct { const char* name; naCFunction func; } funcs[] = {
     { "srand",  f_srand },
     { "abort", f_abort },
     { "directory", f_directory },
+    { "resolvepath", f_resolveDataPath },
     { "parsexml", f_parsexml },
     { "systime", f_systime },
     { "carttogeod", f_carttogeod },
@@ -750,8 +765,7 @@ void FGNasalSys::loadPropertyScripts()
         while((fn = n->getChild("file", j)) != NULL) {
             file_specified = true;
             const char* file = fn->getStringValue();
-            SGPath p(globals->get_fg_root());
-            p.append(file);
+            SGPath p = globals->resolve_maybe_aircraft_path(file);
             loadModule(p, module);
             j++;
         }
@@ -759,7 +773,7 @@ void FGNasalSys::loadPropertyScripts()
         const char* src = n->getStringValue("script");
         if(!n->hasChild("script")) src = 0; // Hrm...
         if(src)
-            createModule(module, n->getPath(), src, strlen(src));
+            createModule(module, n->getPath().c_str(), src, strlen(src));
 
         if(!file_specified && !src)
             SG_LOG(SG_NASAL, SG_ALERT, "Nasal error: " <<
@@ -856,7 +870,7 @@ bool FGNasalSys::handleCommand(const SGPropertyNode* arg)
 {
     const char* nasal = arg->getStringValue("script");
     const char* moduleName = arg->getStringValue("module");
-    naRef code = parse(arg->getPath(true), nasal, strlen(nasal));
+    naRef code = parse(arg->getPath(true).c_str(), nasal, strlen(nasal));
     if(naIsNil(code)) return false;
 
     // Commands can be run "in" a module.  Make sure that module