1
0
Fork 0

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.
This commit is contained in:
andy 2005-06-14 19:57:24 +00:00
parent 6dd82d0502
commit 568d53875e
2 changed files with 9 additions and 6 deletions

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

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