]> git.mxchange.org Git - flightgear.git/commitdiff
Make readScriptFile() public, and rename it to loadModule(), so that external
authorandy <andy>
Tue, 14 Jun 2005 19:57:24 +0000 (19:57 +0000)
committerandy <andy>
Tue, 14 Jun 2005 19:57:24 +0000 (19:57 +0000)
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.

src/Scripting/NasalSys.cxx
src/Scripting/NasalSys.hxx

index e8374bc719101dc7d2fb5b095b575d5371f6ab8f..88cd7e379142fe4a9482ab7faa272d665a920a22 100644 (file)
@@ -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);
index bf6a0abf6d7f57fd6b32de4ace1dfa034c53172c..8efb3159ff0d3a5054ad56240cd8db485b88477e 100644 (file)
@@ -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);