Updated module loading to use a common lua state that has openspace lua functions (closing #100)

This commit is contained in:
Alexander Bock
2015-02-24 13:55:43 +01:00
parent c0d1d9f564
commit c571450dc2
3 changed files with 10 additions and 8 deletions
+1 -1
View File
@@ -136,7 +136,7 @@ private:
};
void loadModules(const std::string& directory, const ghoul::Dictionary& dictionary);
void loadModule(LoadMaps& m,const std::string& modulePath);
void loadModule(LoadMaps& m,const std::string& modulePath, lua_State* state);
void loadNodes(const std::string& parentName, LoadMaps& m);
void loadNode(const ghoul::Dictionary& dictionary);
};
+7 -5
View File
@@ -516,10 +516,12 @@ void SceneGraph::loadModules(
dictionary.getValue(constants::scenegraph::keyCommonFolder, commonDirectory);
FileSys.registerPathToken(_commonModuleToken, commonDirectory);
LDEBUG("Loading common module folder '" << commonDirectory << "'");
lua_State* state = ghoul::lua::createNewLuaState();
OsEng.scriptEngine()->initializeLuaState(state);
LDEBUG("Loading common module folder '" << commonDirectory << "'");
// Load common modules into LoadMaps struct
loadModule(m,FileSys.pathByAppendingComponent(directory, commonDirectory));
loadModule(m, FileSys.pathByAppendingComponent(directory, commonDirectory), state);
// Load the rest of the modules into LoadMaps struct
ghoul::Dictionary moduleDictionary;
@@ -529,7 +531,7 @@ void SceneGraph::loadModules(
for (const std::string& key : keys) {
std::string moduleFolder;
if (moduleDictionary.getValue(key, moduleFolder)) {
loadModule(m,FileSys.pathByAppendingComponent(directory, moduleFolder));
loadModule(m, FileSys.pathByAppendingComponent(directory, moduleFolder), state);
}
}
}
@@ -550,7 +552,7 @@ void SceneGraph::loadModules(
}
}
void SceneGraph::loadModule(LoadMaps& m,const std::string& modulePath) {
void SceneGraph::loadModule(LoadMaps& m,const std::string& modulePath, lua_State* state) {
auto pos = modulePath.find_last_of(ghoul::filesystem::FileSystem::PathSeparator);
if (pos == modulePath.npos) {
LERROR("Bad format for module path: " << modulePath);
@@ -561,7 +563,7 @@ void SceneGraph::loadModule(LoadMaps& m,const std::string& modulePath) {
LDEBUG("Loading nodes from: " << fullModule);
ghoul::Dictionary moduleDictionary;
ghoul::lua::loadDictionaryFromFile(fullModule, moduleDictionary);
ghoul::lua::loadDictionaryFromFile(fullModule, moduleDictionary, state);
std::vector<std::string> keys = moduleDictionary.keys();
for (const std::string& key : keys) {
if (!moduleDictionary.hasValue<ghoul::Dictionary>(key)) {
+2 -2
View File
@@ -470,8 +470,8 @@ void ScriptEngine::remapPrintFunction() {
void ScriptEngine::initializeLuaState(lua_State* state) {
LDEBUG("Create openspace base library");
lua_newtable(_state);
lua_setglobal(_state, _openspaceLibraryName.c_str());
lua_newtable(state);
lua_setglobal(state, _openspaceLibraryName.c_str());
LDEBUG("Add OpenSpace modules");
for (const LuaLibrary& lib : _registeredLibraries)