mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2025-12-31 16:30:07 -06:00
Fix bug where a script execution would stop completely if a property was not found
Added helper file to ease Lua script callback testing Made errors in setPropertyValue and getPropertyValue functions not fatal
This commit is contained in:
Submodule ext/ghoul updated: 41d3165183...740beb2a65
36
include/openspace/scripting/script_helper.h
Normal file
36
include/openspace/scripting/script_helper.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2015 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __SCRIPT_HELPER_H__
|
||||
#define __SCRIPT_HELPER_H__
|
||||
|
||||
#define SCRIPT_CHECK_ARGUMENTS(__stack__, __reqArg__, __realArg__) \
|
||||
if (__realArg__ != __reqArg__) { \
|
||||
LERROR(ghoul::lua::errorLocation(__stack__) << "Expected " << __reqArg__ << \
|
||||
" arguments, got " << __realArg__); \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
|
||||
#endif // __SCRIPT_HELPER_H__
|
||||
@@ -98,7 +98,7 @@ private:
|
||||
std::vector<std::string> _queuedScripts;
|
||||
std::string _currentSyncedScript;
|
||||
};
|
||||
|
||||
|
||||
} // namespace scripting
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
Submodule openspace-data updated: 049eb95dfd...d8bc6ea847
@@ -33,6 +33,7 @@
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/scripting/script_helper.h>
|
||||
#include <openspace/util/constants.h>
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
@@ -69,24 +70,29 @@ namespace luascriptfunctions {
|
||||
* with the type the denoted Property expects
|
||||
*/
|
||||
int property_setValue(lua_State* L) {
|
||||
using ghoul::lua::luaTypeToString;
|
||||
static const std::string _loggerCat = "property_setValue";
|
||||
using ghoul::lua::errorLocation;
|
||||
using ghoul::lua::luaTypeToString;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 2)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
|
||||
SCRIPT_CHECK_ARGUMENTS(L, 2, nArguments);
|
||||
|
||||
std::string uri = luaL_checkstring(L, -2);
|
||||
const int type = lua_type(L, -1);
|
||||
|
||||
openspace::properties::Property* prop = property(uri);
|
||||
if (!prop)
|
||||
return luaL_error(L, "Property with URL '%s' could not be found", uri.c_str());
|
||||
if (!prop) {
|
||||
LERROR(errorLocation(L) << "Property with URI '" << uri << "' was not found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (type != prop->typeLua())
|
||||
return luaL_error(L, "Property '%s' does not accept input of type '%s'. \
|
||||
Requested type: '%s'", uri.c_str(),
|
||||
luaTypeToString(type).c_str(),
|
||||
luaTypeToString(prop->typeLua()).c_str());
|
||||
|
||||
if (type != prop->typeLua()) {
|
||||
LERROR(errorLocation(L) << "Property '" << uri <<
|
||||
"' does not accept input of type '" << luaTypeToString(type) <<
|
||||
"'. Requested type: '" << luaTypeToString(prop->typeLua()) << "'");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
prop->setLua(L);
|
||||
|
||||
@@ -100,15 +106,19 @@ int property_setValue(lua_State* L) {
|
||||
* be passed to the setPropertyValue method.
|
||||
*/
|
||||
int property_getValue(lua_State* L) {
|
||||
static const std::string _loggerCat = "property_getValue";
|
||||
using ghoul::lua::errorLocation;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
SCRIPT_CHECK_ARGUMENTS(L, 1, nArguments);
|
||||
|
||||
std::string uri = luaL_checkstring(L, -1);
|
||||
|
||||
openspace::properties::Property* prop = property(uri);
|
||||
if (!prop)
|
||||
return luaL_error(L, "Property with URL '%s' could not be found", uri.c_str());
|
||||
if (!prop) {
|
||||
LERROR(errorLocation(L) << "Property with URL '" << uri << "' was not found");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
prop->getLua(L);
|
||||
return 1;
|
||||
@@ -121,9 +131,10 @@ int property_getValue(lua_State* L) {
|
||||
* be passed to the setPropertyValue method.
|
||||
*/
|
||||
int loadScene(lua_State* L) {
|
||||
static const std::string _loggerCat = "loadScene";
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
SCRIPT_CHECK_ARGUMENTS(L, 1, nArguments);
|
||||
|
||||
std::string sceneFile = luaL_checkstring(L, -1);
|
||||
|
||||
@@ -163,17 +174,45 @@ bool SceneGraph::initialize()
|
||||
// Start Timing for building SceneGraph shaders
|
||||
typedef std::chrono::high_resolution_clock clock_;
|
||||
typedef std::chrono::duration<double, std::ratio<1> > second_;
|
||||
std::chrono::time_point<clock_> beginning(clock_::now());
|
||||
std::chrono::time_point<clock_> beginning(clock_::now());
|
||||
|
||||
// fboPassthrough program
|
||||
tmpProgram = ProgramObject::Build("fboPassProgram",
|
||||
"${SHADERS}/fboPass_vs.glsl",
|
||||
"${SHADERS}/fboPass_fs.glsl");
|
||||
if (!tmpProgram) return false;
|
||||
tmpProgram->setProgramObjectCallback(cb);
|
||||
_programs.push_back(tmpProgram);
|
||||
OsEng.ref().configurationManager()->setValue("fboPassProgram", tmpProgram);
|
||||
|
||||
// projection program
|
||||
tmpProgram = ProgramObject::Build("projectiveProgram",
|
||||
"${SHADERS}/projectiveTexture_vs.glsl",
|
||||
"${SHADERS}/projectiveTexture_fs.glsl");
|
||||
if (!tmpProgram) return false;
|
||||
tmpProgram->setProgramObjectCallback(cb);
|
||||
_programs.push_back(tmpProgram);
|
||||
OsEng.ref().configurationManager()->setValue("projectiveProgram", tmpProgram);
|
||||
|
||||
// pscstandard
|
||||
tmpProgram = ProgramObject::Build("pscstandard",
|
||||
"${SHADERS}/pscstandard_vs.glsl",
|
||||
"${SHADERS}/pscstandard_fs.glsl");
|
||||
if( ! tmpProgram) return false;
|
||||
tmpProgram->setProgramObjectCallback(cb);
|
||||
|
||||
_programs.push_back(tmpProgram);
|
||||
OsEng.ref().configurationManager()->setValue("pscShader", tmpProgram);
|
||||
|
||||
// pscstandard
|
||||
tmpProgram = ProgramObject::Build("FovProgram",
|
||||
"${SHADERS}/fov_vs.glsl",
|
||||
"${SHADERS}/fov_fs.glsl");
|
||||
if (!tmpProgram) return false;
|
||||
tmpProgram->setProgramObjectCallback(cb);
|
||||
_programs.push_back(tmpProgram);
|
||||
OsEng.ref().configurationManager()->setValue("FovProgram", tmpProgram);
|
||||
|
||||
// RaycastProgram
|
||||
tmpProgram = ProgramObject::Build("RaycastProgram",
|
||||
"${SHADERS}/exitpoints.vert",
|
||||
|
||||
Reference in New Issue
Block a user