From: andy Date: Tue, 14 Jun 2005 19:57:24 +0000 (+0000) Subject: Make readScriptFile() public, and rename it to loadModule(), so that external X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=568d53875e6061956d8778fce1a38afa6d4f6773;p=flightgear.git Make readScriptFile() public, and rename it to loadModule(), so that external code can have access to the facility for loading modules from files. Also includes a cast-int-to-pointer fix that causes a warning on 64 bit systems. --- diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index e8374bc71..88cd7e379 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -86,7 +86,7 @@ FGNasalScript* FGNasalSys::parseScript(const char* src, const char* name) char buf[256]; if(!name) { - sprintf(buf, "FGNasalScript@%8.8x", (int)script); + sprintf(buf, "FGNasalScript@%p", script); name = buf; } @@ -337,7 +337,7 @@ void FGNasalSys::init() fullpath.append(dent->d_name); SGPath file(dent->d_name); if(file.extension() != "nas") continue; - readScriptFile(fullpath, file.base().c_str()); + loadModule(fullpath, file.base().c_str()); } // Pull scripts out of the property tree, too @@ -367,7 +367,7 @@ void FGNasalSys::loadPropertyScripts() const char* file = fn->getStringValue(); SGPath p(globals->get_fg_root()); p.append(file); - readScriptFile(p, module); + loadModule(p, module); j++; } @@ -378,7 +378,7 @@ void FGNasalSys::loadPropertyScripts() if(file) { SGPath p(globals->get_fg_root()); p.append(file); - readScriptFile(p, module); + loadModule(p, module); } */ @@ -411,7 +411,7 @@ void FGNasalSys::logError() // Reads a script file, executes it, and places the resulting // namespace into the global namespace under the specified module // name. -void FGNasalSys::readScriptFile(SGPath file, const char* module) +void FGNasalSys::loadModule(SGPath file, const char* module) { int len = 0; char* buf = readfile(file.c_str(), &len); diff --git a/src/Scripting/NasalSys.hxx b/src/Scripting/NasalSys.hxx index bf6a0abf6..8efb3159f 100644 --- a/src/Scripting/NasalSys.hxx +++ b/src/Scripting/NasalSys.hxx @@ -15,6 +15,10 @@ public: virtual void init(); virtual void update(double dt) { /* noop */ } + // Loads a nasal script from an external file and inserts it as a + // global module of the specified name. + void loadModule(SGPath file, const char* moduleName); + // Simple hook to run arbitrary source code. Returns a bool to // indicate successful execution. Does *not* return any Nasal // values, because handling garbage-collected objects from C space @@ -56,7 +60,6 @@ private: void loadPropertyScripts(); void initModule(const char* moduleName, const char* fileName, const char* src, int len); - void readScriptFile(SGPath file, const char* lib); void hashset(naRef hash, const char* key, naRef val); void logError(); naRef parse(const char* filename, const char* buf, int len);