1
0
Fork 0

Scripting: get rid of gcHash and use new SimGear/Nasal functions.

This commit is contained in:
Thomas Geymayer 2013-10-15 00:58:04 +02:00
parent 7ce2107336
commit 5c42071fbb
13 changed files with 23 additions and 49 deletions

View 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,

View 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,

View 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)

View 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

View 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++) {

View 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

View 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)));

View 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

View 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)

View 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);

View 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

View 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()

View file

@ -172,8 +172,6 @@ private:
SGPropertyNode_ptr _cmdArg;
int _nextGCKey;
naRef _gcHash;
int _callCount;
simgear::BufferedLogCallback* _log;