]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scripting/NasalSys.cxx
rename attributes write/read to writable/readable (The original names
[flightgear.git] / src / Scripting / NasalSys.cxx
index c1e865f04fad536c7b302aa18bbd6d8ba007af57..7b9933627dc4f06355c48d4e57a6ffe5f3e3e65b 100644 (file)
@@ -328,6 +328,8 @@ static naRef f_interpolate(naContext c, naRef me, int argc, naRef* args)
         ->get_group(SGSubsystemMgr::INIT)->get_subsystem("interpolator"))
         ->interpolate(node, nPoints, values, deltas);
 
+    delete[] values;
+    delete[] deltas;
     return naNil();
 }
 
@@ -345,6 +347,12 @@ static naRef f_srand(naContext c, naRef me, int argc, naRef* args)
     return naNum(0);
 }
 
+static naRef f_abort(naContext c, naRef me, int argc, naRef* args)
+{
+    abort();
+    return naNil();
+}
+
 // Return an array listing of all files in a directory
 static naRef f_directory(naContext c, naRef me, int argc, naRef* args)
 {
@@ -544,8 +552,13 @@ static naRef f_airportinfo(naContext c, naRef me, int argc, naRef* args)
             if(rwy._id != id) break;
             if(rwy._type[0] != 'r') continue;
 
+            naRef rwyid = naStr_fromdata(naNewString(c),
+                    const_cast<char *>(rwy._rwy_no.c_str()),
+                    rwy._rwy_no.length());
+
             naRef rwydata = naNewHash(c);
 #define HASHSET(s,l,n) naHash_set(rwydata, naStr_fromdata(naNewString(c),s,l),n)
+            HASHSET("id", 2, rwyid);
             HASHSET("lat", 3, naNum(rwy._lat));
             HASHSET("lon", 3, naNum(rwy._lon));
             HASHSET("heading", 7, naNum(rwy._heading));
@@ -556,11 +569,7 @@ static naRef f_airportinfo(naContext c, naRef me, int argc, naRef* args)
             HASHSET("stopway1", 8, naNum(rwy._stopway1 * SG_FEET_TO_METER));
             HASHSET("stopway2", 8, naNum(rwy._stopway2 * SG_FEET_TO_METER));
 #undef HASHSET
-
-            naRef no = naStr_fromdata(naNewString(c),
-                    const_cast<char *>(rwy._rwy_no.c_str()),
-                    rwy._rwy_no.length());
-            naHash_set(rwys, no, rwydata);
+            naHash_set(rwys, rwyid, rwydata);
         } while(rwylst->next(&rwy));
     }
 
@@ -594,6 +603,7 @@ static struct { const char* name; naCFunction func; } funcs[] = {
     { "_interpolate",  f_interpolate },
     { "rand",  f_rand },
     { "srand",  f_srand },
+    { "abort", f_abort },
     { "directory", f_directory },
     { "parsexml", f_parsexml },
     { "systime", f_systime },
@@ -674,6 +684,19 @@ void FGNasalSys::update(double)
         for(it = _dead_listener.begin(); it != end; ++it) delete *it;
         _dead_listener.clear();
     }
+
+    // The global context is a legacy thing.  We use dynamically
+    // created contexts for naCall() now, so that we can call them
+    // recursively.  But there are still spots that want to use it for
+    // naNew*() calls, which end up leaking memory because the context
+    // only clears out its temporary vector when it's *used*.  So just
+    // junk it and fetch a new/reinitialized one every frame.  This is
+    // clumsy: the right solution would use the dynamic context in all
+    // cases and eliminate _context entirely.  But that's more work,
+    // and this works fine (yes, they say "New" and "Free", but
+    // they're very fast, just trust me). -Andy
+    naFreeContext(_context);
+    _context = naNewContext();
 }
 
 // Loads the scripts found under /nasal in the global tree
@@ -932,7 +955,7 @@ naRef FGNasalSys::setListener(naContext c, int argc, naRef* args)
         return naNil();
     }
 
-    int type = argc > 3 && naIsNum(args[3]) ? args[3].num : 1;
+    int type = argc > 3 && naIsNum(args[3]) ? (int)args[3].num : 1;
     FGNasalListener *nl = new FGNasalListener(node, code, this,
             gcSave(code), _listenerId, type);
 
@@ -1066,12 +1089,11 @@ bool FGNasalListener::changed(SGPropertyNode* node)
 void FGNasalModelData::modelLoaded(const string& path, SGPropertyNode *prop,
                                    osg::Node *)
 {
-    SGPropertyNode *n = prop->getNode("nasal"), *load;
-    if(!n)
+    if(!prop)
         return;
 
-    load = n->getNode("load");
-    _unload = n->getNode("unload");
+    SGPropertyNode *load = prop->getNode("load");
+    _unload = prop->getNode("unload");
     if(!load && !_unload)
         return;