Scripting: get rid of gcHash and use new SimGear/Nasal functions.
This commit is contained in:
parent
7ce2107336
commit
5c42071fbb
13 changed files with 23 additions and 49 deletions
|
@ -122,18 +122,6 @@ namespace canvas
|
||||||
return getNasalSys()->context();
|
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 FGCanvasSystemAdapter::callMethod( naRef code,
|
||||||
naRef self,
|
naRef self,
|
||||||
|
|
|
@ -33,8 +33,6 @@ namespace canvas
|
||||||
virtual osg::Image* getImage(const std::string& path) const;
|
virtual osg::Image* getImage(const std::string& path) const;
|
||||||
|
|
||||||
virtual naContext getNasalContext() const;
|
virtual naContext getNasalContext() const;
|
||||||
virtual int gcSave(naRef r);
|
|
||||||
virtual void gcRelease(int key);
|
|
||||||
virtual naRef callMethod( naRef code,
|
virtual naRef callMethod( naRef code,
|
||||||
naRef self,
|
naRef self,
|
||||||
int argc,
|
int argc,
|
||||||
|
|
|
@ -202,7 +202,7 @@ naRef to_nasal_helper(naContext c, const sc::ElementWeakPtr& el)
|
||||||
return NasalElement::create(c, el.lock());
|
return NasalElement::create(c, el.lock());
|
||||||
}
|
}
|
||||||
|
|
||||||
naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave)
|
naRef initNasalCanvas(naRef globals, naContext c)
|
||||||
{
|
{
|
||||||
NasalEvent::init("canvas.Event")
|
NasalEvent::init("canvas.Event")
|
||||||
.member("type", &sc::Event::getTypeString)
|
.member("type", &sc::Event::getTypeString)
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
#include <simgear/nasal/nasal.h>
|
#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
|
#endif // of SCRIPTING_NASAL_CANVAS_HXX
|
||||||
|
|
||||||
|
|
|
@ -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);
|
conditionPrototype = naNewHash(c);
|
||||||
hashset(c, gcSave, "conditionProto", conditionPrototype);
|
naSave(c, conditionPrototype);
|
||||||
|
|
||||||
hashset(c, conditionPrototype, "test", naNewFunc(c, naNewCCode(c, f_condition_test)));
|
hashset(c, conditionPrototype, "test", naNewFunc(c, naNewCCode(c, f_condition_test)));
|
||||||
for(int i=0; funcs[i].name; i++) {
|
for(int i=0; funcs[i].name; i++) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ class SGCondition;
|
||||||
|
|
||||||
naRef ghostForCondition(naContext c, const SGCondition* cond);
|
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
|
#endif // of SCRIPTING_NASAL_CONDITION_HXX
|
||||||
|
|
||||||
|
|
|
@ -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);
|
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, "runway", naNewFunc(c, naNewCCode(c, f_airport_runway)));
|
||||||
hashset(c, airportPrototype, "runwaysWithoutReciprocals", naNewFunc(c, naNewCCode(c, f_airport_runwaysWithoutReciprocals)));
|
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)));
|
hashset(c, airportPrototype, "tostring", naNewFunc(c, naNewCCode(c, f_airport_toString)));
|
||||||
|
|
||||||
flightplanPrototype = naNewHash(c);
|
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, "getWP", naNewFunc(c, naNewCCode(c, f_flightplan_getWP)));
|
||||||
hashset(c, flightplanPrototype, "currentWP", naNewFunc(c, naNewCCode(c, f_flightplan_currentWP)));
|
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)));
|
hashset(c, flightplanPrototype, "finish", naNewFunc(c, naNewCCode(c, f_flightplan_finish)));
|
||||||
|
|
||||||
waypointPrototype = naNewHash(c);
|
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, "navaid", naNewFunc(c, naNewCCode(c, f_waypoint_navaid)));
|
||||||
hashset(c, waypointPrototype, "runway", naNewFunc(c, naNewCCode(c, f_waypoint_runway)));
|
hashset(c, waypointPrototype, "runway", naNewFunc(c, naNewCCode(c, f_waypoint_runway)));
|
||||||
hashset(c, waypointPrototype, "airport", naNewFunc(c, naNewCCode(c, f_waypoint_airport)));
|
hashset(c, waypointPrototype, "airport", naNewFunc(c, naNewCCode(c, f_waypoint_airport)));
|
||||||
|
|
||||||
procedurePrototype = naNewHash(c);
|
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, "transition", naNewFunc(c, naNewCCode(c, f_procedure_transition)));
|
||||||
hashset(c, procedurePrototype, "route", naNewFunc(c, naNewCCode(c, f_procedure_route)));
|
hashset(c, procedurePrototype, "route", naNewFunc(c, naNewCCode(c, f_procedure_route)));
|
||||||
|
|
||||||
fpLegPrototype = naNewHash(c);
|
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, "setSpeed", naNewFunc(c, naNewCCode(c, f_leg_setSpeed)));
|
||||||
hashset(c, fpLegPrototype, "setAltitude", naNewFunc(c, naNewCCode(c, f_leg_setAltitude)));
|
hashset(c, fpLegPrototype, "setAltitude", naNewFunc(c, naNewCCode(c, f_leg_setAltitude)));
|
||||||
hashset(c, fpLegPrototype, "path", naNewFunc(c, naNewCCode(c, f_leg_path)));
|
hashset(c, fpLegPrototype, "path", naNewFunc(c, naNewCCode(c, f_leg_path)));
|
||||||
|
|
|
@ -28,8 +28,8 @@ class SGGeod;
|
||||||
|
|
||||||
bool geodFromHash(naRef ref, SGGeod& result);
|
bool geodFromHash(naRef ref, SGGeod& result);
|
||||||
|
|
||||||
naRef initNasalPositioned(naRef globals, naContext c, naRef gcSave);
|
naRef initNasalPositioned(naRef globals, naContext c);
|
||||||
naRef initNasalPositioned_cppbind(naRef globals, naContext c, naRef gcSave);
|
naRef initNasalPositioned_cppbind(naRef globals, naContext c);
|
||||||
void postinitNasalPositioned(naRef globals, naContext c);
|
void postinitNasalPositioned(naRef globals, naContext c);
|
||||||
|
|
||||||
#endif // of SCRIPTING_NASAL_POSITIONED_HXX
|
#endif // of SCRIPTING_NASAL_POSITIONED_HXX
|
||||||
|
|
|
@ -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")
|
NasalPositioned::init("Positioned")
|
||||||
.member("id", &FGPositioned::ident)
|
.member("id", &FGPositioned::ident)
|
||||||
|
|
|
@ -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);
|
nasal::Hash string_module(string, c);
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include <simgear/nasal/nasal.h>
|
#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
|
#endif // of SCRIPTING_NASAL_STRING_HXX
|
||||||
|
|
||||||
|
|
|
@ -202,8 +202,6 @@ FGNasalSys::FGNasalSys()
|
||||||
_context = 0;
|
_context = 0;
|
||||||
_globals = naNil();
|
_globals = naNil();
|
||||||
_string = naNil();
|
_string = naNil();
|
||||||
_gcHash = naNil();
|
|
||||||
_nextGCKey = 0; // Any value will do
|
|
||||||
_callCount = 0;
|
_callCount = 0;
|
||||||
|
|
||||||
_log = new simgear::BufferedLogCallback(SG_NASAL, SG_INFO);
|
_log = new simgear::BufferedLogCallback(SG_NASAL, SG_INFO);
|
||||||
|
@ -778,22 +776,16 @@ void FGNasalSys::init()
|
||||||
// And our SGPropertyNode wrapper
|
// And our SGPropertyNode wrapper
|
||||||
hashset(_globals, "props", genPropsModule());
|
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
|
// Add string methods
|
||||||
_string = naInit_string(_context);
|
_string = naInit_string(_context);
|
||||||
naSave(_context, _string);
|
naSave(_context, _string);
|
||||||
initNasalString(_globals, _string, _context, _gcHash);
|
initNasalString(_globals, _string, _context);
|
||||||
|
|
||||||
initNasalPositioned(_globals, _context, _gcHash);
|
initNasalPositioned(_globals, _context);
|
||||||
initNasalPositioned_cppbind(_globals, _context, _gcHash);
|
initNasalPositioned_cppbind(_globals, _context);
|
||||||
NasalClipboard::init(this);
|
NasalClipboard::init(this);
|
||||||
initNasalCanvas(_globals, _context, _gcHash);
|
initNasalCanvas(_globals, _context);
|
||||||
initNasalCondition(_globals, _context, _gcHash);
|
initNasalCondition(_globals, _context);
|
||||||
|
|
||||||
NasalTimerObj::init("Timer")
|
NasalTimerObj::init("Timer")
|
||||||
.method("start", &TimerObj::start)
|
.method("start", &TimerObj::start)
|
||||||
|
@ -1174,14 +1166,12 @@ void FGNasalSys::handleTimer(NasalTimer* t)
|
||||||
|
|
||||||
int FGNasalSys::gcSave(naRef r)
|
int FGNasalSys::gcSave(naRef r)
|
||||||
{
|
{
|
||||||
int key = _nextGCKey++;
|
return naGCSave(r);
|
||||||
naHash_set(_gcHash, naNum(key), r);
|
|
||||||
return key;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGNasalSys::gcRelease(int key)
|
void FGNasalSys::gcRelease(int key)
|
||||||
{
|
{
|
||||||
naHash_delete(_gcHash, naNum(key));
|
naGCRelease(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGNasalSys::NasalTimer::timerExpired()
|
void FGNasalSys::NasalTimer::timerExpired()
|
||||||
|
|
|
@ -172,8 +172,6 @@ private:
|
||||||
|
|
||||||
SGPropertyNode_ptr _cmdArg;
|
SGPropertyNode_ptr _cmdArg;
|
||||||
|
|
||||||
int _nextGCKey;
|
|
||||||
naRef _gcHash;
|
|
||||||
int _callCount;
|
int _callCount;
|
||||||
|
|
||||||
simgear::BufferedLogCallback* _log;
|
simgear::BufferedLogCallback* _log;
|
||||||
|
|
Loading…
Add table
Reference in a new issue