Fixed bug where ScriptEngine would complain about double-added libraries

Correct application of default keybinding
This commit is contained in:
Alexander Bock
2015-02-25 17:57:25 +01:00
parent e155e7ec9f
commit d249e9422e
3 changed files with 9 additions and 10 deletions

View File

@@ -85,7 +85,7 @@ private:
bool registerLuaLibrary(lua_State* state, const LuaLibrary& library);
void addLibraryFunctions(lua_State* state, const LuaLibrary& library, bool replace);
bool isLibraryNameAllowed(const std::string& name);
bool isLibraryNameAllowed(lua_State* state, const std::string& name);
void addBaseLibrary();
void remapPrintFunction();

View File

@@ -10,7 +10,7 @@ openspace.time.setTime("2007 FEB 27 16:40:00") -- This is the start tim
openspace.time.setDeltaTime(10) -- How many seconds pass per second of realtime, changeable in the GUI
dofile(openspace.absPath('${SCRIPTS}/bind_keys.lua'))() -- Load the default keybindings
dofile(openspace.absPath('${SCRIPTS}/bind_keys.lua')) -- Load the default keybindings
-- openspace.time.setDeltaTime(50);

View File

@@ -324,17 +324,16 @@ bool ScriptEngine::hasLibrary(const std::string& name)
//return false;
}
bool ScriptEngine::isLibraryNameAllowed(const std::string& name)
{
bool ScriptEngine::isLibraryNameAllowed(lua_State* state, const std::string& name) {
bool result = false;
lua_getglobal(_state, _openspaceLibraryName.c_str());
const bool hasOpenSpaceLibrary = lua_istable(_state, -1);
lua_getglobal(state, _openspaceLibraryName.c_str());
const bool hasOpenSpaceLibrary = lua_istable(state, -1);
if (!hasOpenSpaceLibrary) {
LFATAL("OpenSpace library was not created in initialize method");
return false;
}
lua_getfield(_state, -1, name.c_str());
const int type = lua_type(_state, -1);
lua_getfield(state, -1, name.c_str());
const int type = lua_type(state, -1);
switch (type) {
case LUA_TNONE:
case LUA_TNIL:
@@ -370,7 +369,7 @@ bool ScriptEngine::isLibraryNameAllowed(const std::string& name)
break;
}
lua_pop(_state, 2);
lua_pop(state, 2);
return result;
}
@@ -496,7 +495,7 @@ bool ScriptEngine::registerLuaLibrary(lua_State* state, const LuaLibrary& librar
//ghoul::lua::logStack(_state);
}
else {
const bool allowed = isLibraryNameAllowed(library.name);
const bool allowed = isLibraryNameAllowed(state, library.name);
if (!allowed)
return false;