]> git.mxchange.org Git - flightgear.git/commitdiff
Scripting: get rid of gcHash and use new SimGear/Nasal functions.
authorThomas Geymayer <tomgey@gmail.com>
Mon, 14 Oct 2013 22:58:04 +0000 (00:58 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Mon, 14 Oct 2013 22:58:21 +0000 (00:58 +0200)
13 files changed:
src/Canvas/FGCanvasSystemAdapter.cxx
src/Canvas/FGCanvasSystemAdapter.hxx
src/Scripting/NasalCanvas.cxx
src/Scripting/NasalCanvas.hxx
src/Scripting/NasalCondition.cxx
src/Scripting/NasalCondition.hxx
src/Scripting/NasalPositioned.cxx
src/Scripting/NasalPositioned.hxx
src/Scripting/NasalPositioned_cppbind.cxx
src/Scripting/NasalString.cxx
src/Scripting/NasalString.hxx
src/Scripting/NasalSys.cxx
src/Scripting/NasalSys.hxx

index 576e859b1cecdbc3b5e5b014bc04235550a8fa6a..a587dff16b27f17a40593a27338da78f1dd6b948 100644 (file)
@@ -122,18 +122,6 @@ namespace canvas
     return getNasalSys()->context();
   }
 
-  //----------------------------------------------------------------------------
-  int FGCanvasSystemAdapter::gcSave(naRef r)
-  {
-    return getNasalSys()->gcSave(r);
-  }
-
-  //----------------------------------------------------------------------------
-  void FGCanvasSystemAdapter::gcRelease(int key)
-  {
-    getNasalSys()->gcRelease(key);
-  }
-
   //------------------------------------------------------------------------------
   naRef FGCanvasSystemAdapter::callMethod( naRef code,
                                            naRef self,
index 4cb3a5547f8be3e8a5d4b07bfd0f487663856172..7fca339f1f544726eae9155e8d9122e529138c18 100644 (file)
@@ -33,8 +33,6 @@ namespace canvas
       virtual osg::Image* getImage(const std::string& path) const;
 
       virtual naContext getNasalContext() const;
-      virtual int gcSave(naRef r);
-      virtual void gcRelease(int key);
       virtual naRef callMethod( naRef code,
                                 naRef self,
                                 int argc,
index 1cdf9b57f5675500ce227e04c15c537cc69dd55f..67d9f728aec7cf5f899594957b8bdf79d07d6814 100644 (file)
@@ -202,7 +202,7 @@ naRef to_nasal_helper(naContext c, const sc::ElementWeakPtr& el)
   return NasalElement::create(c, el.lock());
 }
 
-naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave)
+naRef initNasalCanvas(naRef globals, naContext c)
 {
   NasalEvent::init("canvas.Event")
     .member("type", &sc::Event::getTypeString)
index 394a1194beb64453d302d26095fb499e27bde050..090230132f4ed44bd169f08d82dcc6676ac8a239 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <simgear/nasal/nasal.h>
 
-naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave);
+naRef initNasalCanvas(naRef globals, naContext c);
 
 #endif // of SCRIPTING_NASAL_CANVAS_HXX
 
index da796c533ffa84b2a9a194017f9c6eb846ce1e4f..f47a52a51b84b0cc6c281577a562dc3cab6b9169 100644 (file)
@@ -100,10 +100,10 @@ static struct { const char* name; naCFunction func; } funcs[] = {
 };
 
 
-naRef initNasalCondition(naRef globals, naContext c, naRef gcSave)
+naRef initNasalCondition(naRef globals, naContext c)
 {
   conditionPrototype = naNewHash(c);
-  hashset(c, gcSave, "conditionProto", conditionPrototype);
+  naSave(c, conditionPrototype);
   
   hashset(c, conditionPrototype, "test", naNewFunc(c, naNewCCode(c, f_condition_test)));  
   for(int i=0; funcs[i].name; i++) {
index 51b2661b65f6bfc2eed27ea0ca4284faeeafbf2f..c16b2b5d17e000c4bb3fefb7bfd7df27de93e304 100644 (file)
@@ -28,7 +28,7 @@ class SGCondition;
 
 naRef ghostForCondition(naContext c, const SGCondition* cond);
 
-naRef initNasalCondition(naRef globals, naContext c, naRef gcSave);
+naRef initNasalCondition(naRef globals, naContext c);
 
 #endif // of SCRIPTING_NASAL_CONDITION_HXX
 
index fced59becc44b03c51c99a0e28175f8985768835..5b5206eedcdd11544e15f036da0382bcc8582030 100644 (file)
@@ -2403,10 +2403,10 @@ static struct { const char* name; naCFunction func; } funcs[] = {
 };
 
 
-naRef initNasalPositioned(naRef globals, naContext c, naRef gcSave)
+naRef initNasalPositioned(naRef globals, naContext c)
 {
     airportPrototype = naNewHash(c);
-    hashset(c, gcSave, "airportProto", airportPrototype);
+    naSave(c, airportPrototype);
   
     hashset(c, airportPrototype, "runway", naNewFunc(c, naNewCCode(c, f_airport_runway)));
     hashset(c, airportPrototype, "runwaysWithoutReciprocals", naNewFunc(c, naNewCCode(c, f_airport_runwaysWithoutReciprocals)));
@@ -2424,7 +2424,7 @@ naRef initNasalPositioned(naRef globals, naContext c, naRef gcSave)
     hashset(c, airportPrototype, "tostring", naNewFunc(c, naNewCCode(c, f_airport_toString)));
   
     flightplanPrototype = naNewHash(c);
-    hashset(c, gcSave, "flightplanProto", flightplanPrototype);
+    naSave(c, flightplanPrototype);
       
     hashset(c, flightplanPrototype, "getWP", naNewFunc(c, naNewCCode(c, f_flightplan_getWP)));
     hashset(c, flightplanPrototype, "currentWP", naNewFunc(c, naNewCCode(c, f_flightplan_currentWP))); 
@@ -2442,19 +2442,19 @@ naRef initNasalPositioned(naRef globals, naContext c, naRef gcSave)
     hashset(c, flightplanPrototype, "finish", naNewFunc(c, naNewCCode(c, f_flightplan_finish)));
     
     waypointPrototype = naNewHash(c);
-    hashset(c, gcSave, "wayptProto", waypointPrototype);
+    naSave(c, waypointPrototype);
     
     hashset(c, waypointPrototype, "navaid", naNewFunc(c, naNewCCode(c, f_waypoint_navaid)));
     hashset(c, waypointPrototype, "runway", naNewFunc(c, naNewCCode(c, f_waypoint_runway)));
     hashset(c, waypointPrototype, "airport", naNewFunc(c, naNewCCode(c, f_waypoint_airport)));
   
     procedurePrototype = naNewHash(c);
-    hashset(c, gcSave, "procedureProto", procedurePrototype);
+    naSave(c, procedurePrototype);
     hashset(c, procedurePrototype, "transition", naNewFunc(c, naNewCCode(c, f_procedure_transition)));
     hashset(c, procedurePrototype, "route", naNewFunc(c, naNewCCode(c, f_procedure_route)));
   
     fpLegPrototype = naNewHash(c);
-    hashset(c, gcSave, "fpLegProto", fpLegPrototype);
+    naSave(c, fpLegPrototype);
     hashset(c, fpLegPrototype, "setSpeed", naNewFunc(c, naNewCCode(c, f_leg_setSpeed)));
     hashset(c, fpLegPrototype, "setAltitude", naNewFunc(c, naNewCCode(c, f_leg_setAltitude)));
     hashset(c, fpLegPrototype, "path", naNewFunc(c, naNewCCode(c, f_leg_path)));
index 14401e9c2c08678f476213895279b4702e62435e..f30ee6fc8606ff739a38ea0135ec7159e61f8c28 100644 (file)
@@ -28,8 +28,8 @@ class SGGeod;
 
 bool geodFromHash(naRef ref, SGGeod& result); 
 
-naRef initNasalPositioned(naRef globals, naContext c, naRef gcSave);
-naRef initNasalPositioned_cppbind(naRef globals, naContext c, naRef gcSave);
+naRef initNasalPositioned(naRef globals, naContext c);
+naRef initNasalPositioned_cppbind(naRef globals, naContext c);
 void postinitNasalPositioned(naRef globals, naContext c);
 
 #endif // of SCRIPTING_NASAL_POSITIONED_HXX
index b2e10444224d0ed64dd6d9c2088acced0342e474..8d51624a88ea46daed72e174daca23e53841fb9c 100644 (file)
@@ -457,7 +457,7 @@ static naRef f_sortByRange(nasal::CallContext ctx)
 }
 
 //------------------------------------------------------------------------------
-naRef initNasalPositioned_cppbind(naRef globalsRef, naContext c, naRef gcSave)
+naRef initNasalPositioned_cppbind(naRef globalsRef, naContext c)
 {
   NasalPositioned::init("Positioned")
     .member("id", &FGPositioned::ident)
index c3aaf609ea893fc449e0b6bcc368eeec00ad8deb..331c75ffb6ab53a7b1d1fc6ae69c306148f159a7 100644 (file)
@@ -131,7 +131,7 @@ static naRef f_find_first_not_of(naContext c, naRef me, int argc, naRef* args)
 }
 
 //------------------------------------------------------------------------------
-naRef initNasalString(naRef globals, naRef string, naContext c, naRef gcSave)
+naRef initNasalString(naRef globals, naRef string, naContext c)
 {
   nasal::Hash string_module(string, c);
 
index 80d6474d581938425984c88572fcd41e5e2f0372..5baba39d8ea6eb92de31bd32d4ccaa333c3a829b 100644 (file)
@@ -21,7 +21,7 @@
 
 #include <simgear/nasal/nasal.h>
 
-naRef initNasalString(naRef globals, naRef string, naContext c, naRef gcSave);
+naRef initNasalString(naRef globals, naRef string, naContext c);
 
 #endif // of SCRIPTING_NASAL_STRING_HXX
 
index d4c1ae0e25d9ba89594ebefda4b164b89d73ed60..278f97194b6f47513c0d35814b50fe0c3a2645f0 100644 (file)
@@ -202,8 +202,6 @@ FGNasalSys::FGNasalSys()
     _context = 0;
     _globals = naNil();
     _string = naNil();
-    _gcHash = naNil();
-    _nextGCKey = 0; // Any value will do
     _callCount = 0;
     
     _log = new simgear::BufferedLogCallback(SG_NASAL, SG_INFO);
@@ -778,22 +776,16 @@ void FGNasalSys::init()
     // And our SGPropertyNode wrapper
     hashset(_globals, "props", genPropsModule());
 
-    // Make a "__gcsave" hash to hold the naRef objects which get
-    // passed to handles outside the interpreter (to protect them from
-    // begin garbage-collected).
-    _gcHash = naNewHash(_context);
-    hashset(_globals, "__gcsave", _gcHash);
-
     // Add string methods
     _string = naInit_string(_context);
     naSave(_context, _string);
-    initNasalString(_globals, _string, _context, _gcHash);
+    initNasalString(_globals, _string, _context);
 
-    initNasalPositioned(_globals, _context, _gcHash);
-    initNasalPositioned_cppbind(_globals, _context, _gcHash);
+    initNasalPositioned(_globals, _context);
+    initNasalPositioned_cppbind(_globals, _context);
     NasalClipboard::init(this);
-    initNasalCanvas(_globals, _context, _gcHash);
-    initNasalCondition(_globals, _context, _gcHash);
+    initNasalCanvas(_globals, _context);
+    initNasalCondition(_globals, _context);
   
     NasalTimerObj::init("Timer")
       .method("start", &TimerObj::start)
@@ -1174,14 +1166,12 @@ void FGNasalSys::handleTimer(NasalTimer* t)
 
 int FGNasalSys::gcSave(naRef r)
 {
-    int key = _nextGCKey++;
-    naHash_set(_gcHash, naNum(key), r);
-    return key;
+    return naGCSave(r);
 }
 
 void FGNasalSys::gcRelease(int key)
 {
-    naHash_delete(_gcHash, naNum(key));
+    naGCRelease(key);
 }
 
 void FGNasalSys::NasalTimer::timerExpired()
index 973730e4770f99eb19b77eb9ff0012e195ce6dab..692cb3c7795b7a7d52af5b0f99915d3a59dc0ef6 100644 (file)
@@ -172,8 +172,6 @@ private:
 
     SGPropertyNode_ptr _cmdArg;
 
-    int _nextGCKey;
-    naRef _gcHash;
     int _callCount;
 
     simgear::BufferedLogCallback* _log;