X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FScripting%2FNasalSys.cxx;h=aee1dc54d94e4b556f81d4c14fead7fa8a2d0be8;hb=12076bce0e9fb66286f14931e8f4eb12fc0b9b82;hp=b65264a8be78a87da896542044c9fa6c4f1c770d;hpb=373d511c6948ae4737b183e0ac38471544b6f499;p=flightgear.git diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index b65264a8b..aee1dc54d 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -13,7 +13,6 @@ #include #include #include -#include // for std::sort #include #include @@ -27,10 +26,15 @@ #include "NasalSys.hxx" #include "NasalPositioned.hxx" +#include "NasalCanvas.hxx" +#include "NasalClipboard.hxx" +#include "NasalCondition.hxx" + #include
#include
#include
+ using std::map; static FGNasalSys* nasalSys = 0; @@ -99,6 +103,20 @@ FGNasalSys::FGNasalSys() _callCount = 0; } +// Utility. Sets a named key in a hash by C string, rather than nasal +// string object. +void FGNasalSys::hashset(naRef hash, const char* key, naRef val) +{ + naRef s = naNewString(_context); + naStr_fromdata(s, (char*)key, strlen(key)); + naHash_set(hash, s, val); +} + +void FGNasalSys::globalsSet(const char* key, naRef val) +{ + hashset(_globals, key, val); +} + naRef FGNasalSys::call(naRef code, int argc, naRef* args, naRef locals) { return callMethod(code, naNil(), argc, args, locals); @@ -168,15 +186,6 @@ FGNasalScript* FGNasalSys::parseScript(const char* src, const char* name) return script; } -// Utility. Sets a named key in a hash by C string, rather than nasal -// string object. -void FGNasalSys::hashset(naRef hash, const char* key, naRef val) -{ - naRef s = naNewString(_context); - naStr_fromdata(s, (char*)key, strlen(key)); - naHash_set(hash, s, val); -} - // The get/setprop functions accept a *list* of strings and walk // through the property tree with them to find the appropriate node. // This allows a Nasal object to hold onto a property path and use it @@ -216,7 +225,7 @@ static naRef f_getprop(naContext c, naRef me, int argc, naRef* args) case props::DOUBLE: { double dv = p->getDoubleValue(); - if (osg::isNaN(dv)) { + if (SGMisc::isNaN(dv)) { SG_LOG(SG_NASAL, SG_ALERT, "Nasal getprop: property " << p->getPath() << " is NaN"); return naNil(); } @@ -271,7 +280,7 @@ static naRef f_setprop(naContext c, naRef me, int argc, naRef* args) if(naIsNil(n)) naRuntimeError(c, "setprop() value is not string or number"); - if (osg::isNaN(n.num)) { + if (SGMisc::isNaN(n.num)) { naRuntimeError(c, "setprop() passed a NaN"); } @@ -548,6 +557,9 @@ void FGNasalSys::init() hashset(_globals, "__gcsave", _gcHash); initNasalPositioned(_globals, _context, _gcHash); + NasalClipboard::init(this); + initNasalCanvas(_globals, _context, _gcHash); + initNasalCondition(_globals, _context, _gcHash); // Now load the various source files in the Nasal directory simgear::Dir nasalDir(SGPath(globals->get_fg_root(), "Nasal")); @@ -577,6 +589,9 @@ void FGNasalSys::init() void FGNasalSys::update(double) { + if( NasalClipboard::getInstance() ) + NasalClipboard::getInstance()->update(); + if(!_dead_listener.empty()) { vector::iterator it, end = _dead_listener.end(); for(it = _dead_listener.begin(); it != end; ++it) delete *it; @@ -619,10 +634,8 @@ bool pathSortPredicate(const SGPath& p1, const SGPath& p2) void FGNasalSys::loadScriptDirectory(simgear::Dir nasalDir) { simgear::PathList scripts = nasalDir.children(simgear::Dir::TYPE_FILE, ".nas"); - // sort scripts, avoid loading sequence effects due to file system's - // random directory order - std::sort(scripts.begin(), scripts.end(), pathSortPredicate); - + // Note: simgear::Dir already reports file entries in a deterministic order, + // so a fixed loading sequence is guaranteed (same for every user) for (unsigned int i=0; i