mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-22 02:48:25 -05:00
Simplify script precondition argument checks
This commit is contained in:
@@ -323,7 +323,6 @@ set(OPENSPACE_HEADER
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/scene/scenelicensewriter.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/scene/scenegraphnode.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/scripting/lualibrary.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/scripting/script_helper.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/scripting/scriptengine.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/scripting/scriptscheduler.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/scripting/systemcapabilitiesbinding.h
|
||||
|
||||
@@ -33,13 +33,12 @@ namespace openspace::luascriptfunctions {
|
||||
* Checks whether the passed OpenSpaceModule is loaded or not
|
||||
*/
|
||||
int isLoaded(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::isLoaded");
|
||||
|
||||
const int type = lua_type(L, -1);
|
||||
if (type != LUA_TSTRING)
|
||||
if (type != LUA_TSTRING) {
|
||||
return luaL_error(L, "Expected argument of type 'string'");
|
||||
}
|
||||
std::string moduleName = lua_tostring(L, -1);
|
||||
|
||||
std::vector<OpenSpaceModule*> modules = OsEng.moduleEngine().modules();
|
||||
@@ -52,10 +51,12 @@ int isLoaded(lua_State* L) {
|
||||
}
|
||||
);
|
||||
|
||||
if (it != modules.end())
|
||||
if (it != modules.end()) {
|
||||
lua_pushboolean(L, 1);
|
||||
else
|
||||
}
|
||||
else {
|
||||
lua_pushboolean(L, 0);
|
||||
}
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 1, "Incorrect number of items left on stack");
|
||||
return 1;
|
||||
|
||||
@@ -34,10 +34,7 @@
|
||||
namespace luascriptfunctions {
|
||||
|
||||
int setSynchronization(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::setSynchronization");
|
||||
|
||||
bool b = lua_toboolean(L, -1) != 0;
|
||||
OsEng.windowWrapper().setSynchronization(b);
|
||||
|
||||
@@ -34,10 +34,7 @@ namespace openspace::luascriptfunctions {
|
||||
int bindKey(lua_State* L) {
|
||||
using ghoul::lua::luaTypeToString;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 2 && nArguments != 3) {
|
||||
return luaL_error(L, "Expected %i or %i arguments, got %i", 2, 3, nArguments);
|
||||
}
|
||||
int nArguments = ghoul::lua::checkArgumentsAndThrow(L, 2, 3, "lua::bindKey");
|
||||
|
||||
int KeyLocation = nArguments == 3 ? -3 : -2;
|
||||
int CommandLocation = nArguments == 3 ? -2 : -1;
|
||||
@@ -69,7 +66,7 @@ int bindKey(lua_State* L) {
|
||||
std::move(documentation)
|
||||
);
|
||||
|
||||
lua_settop(L, 0);
|
||||
lua_pop(L, nArguments);
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
@@ -82,10 +79,8 @@ int bindKey(lua_State* L) {
|
||||
int bindKeyLocal(lua_State* L) {
|
||||
using ghoul::lua::luaTypeToString;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 2 && nArguments != 3) {
|
||||
return luaL_error(L, "Expected %i or %i arguments, got %i", 2, 3, nArguments);
|
||||
}
|
||||
int nArguments = ghoul::lua::checkArgumentsAndThrow(L, 2, 3, "lua::bindKeyLocal");
|
||||
|
||||
|
||||
int KeyLocation = nArguments == 3 ? -3 : -2;
|
||||
int CommandLocation = nArguments == 3 ? -2 : -1;
|
||||
@@ -115,9 +110,9 @@ int bindKeyLocal(lua_State* L) {
|
||||
iKey.modifier,
|
||||
std::move(command),
|
||||
std::move(documentation)
|
||||
);
|
||||
);
|
||||
|
||||
lua_settop(L, 0);
|
||||
lua_pop(L, nArguments);
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
@@ -129,13 +124,9 @@ int bindKeyLocal(lua_State* L) {
|
||||
* local or remote key binds
|
||||
*/
|
||||
int getKeyBindings(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::getKeyBindings");
|
||||
|
||||
std::string key = luaL_checkstring(L, -1);
|
||||
lua_settop(L, 0);
|
||||
std::string key = ghoul::lua::checkStringAndPop(L);
|
||||
|
||||
using KeyInformation = interaction::KeyBindingManager::KeyInformation;
|
||||
|
||||
@@ -169,13 +160,9 @@ int getKeyBindings(lua_State* L) {
|
||||
* Clears the keybinding of the key named as argument
|
||||
*/
|
||||
int clearKey(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::clearKey");
|
||||
|
||||
std::string key = luaL_checkstring(L, -1);
|
||||
lua_settop(L, 0);
|
||||
std::string key = ghoul::lua::checkStringAndPop(L);
|
||||
|
||||
OsEng.keyBindingManager().removeKeyBinding(key);
|
||||
|
||||
@@ -189,10 +176,7 @@ int clearKey(lua_State* L) {
|
||||
* Clears all key bindings
|
||||
*/
|
||||
int clearKeys(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::clearKeys");
|
||||
|
||||
OsEng.keyBindingManager().resetKeyBindings();
|
||||
|
||||
|
||||
@@ -25,30 +25,24 @@
|
||||
namespace openspace::luascriptfunctions {
|
||||
|
||||
int restoreCameraStateFromFile(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::restoreCameraStateFromFile");
|
||||
|
||||
using ghoul::lua::luaTypeToString;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
|
||||
std::string cameraStateFilePath = luaL_checkstring(L, -1);
|
||||
lua_settop(L, 0);
|
||||
std::string cameraStateFilePath = ghoul::lua::checkStringAndPop(L);
|
||||
|
||||
if (cameraStateFilePath.empty()) {
|
||||
return luaL_error(L, "filepath string is empty");
|
||||
}
|
||||
|
||||
OsEng.navigationHandler().restoreCameraStateFromFile(cameraStateFilePath);
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setCameraState(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::setCameraState");
|
||||
|
||||
try {
|
||||
ghoul::Dictionary dictionary;
|
||||
@@ -59,40 +53,37 @@ int setCameraState(lua_State* L) {
|
||||
return luaL_error(L, "Could not set camera state: %s", e.what());
|
||||
}
|
||||
|
||||
// @CLEANUP: When luaDictionaryFromState doesn't leak space anymore, remove the next
|
||||
// line ---abock(2018-02-15)
|
||||
lua_settop(L, 0);
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int saveCameraStateToFile(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::saveCameraStateToFile");
|
||||
|
||||
using ghoul::lua::luaTypeToString;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
|
||||
std::string cameraStateFilePath = luaL_checkstring(L, -1);
|
||||
lua_settop(L, 0);
|
||||
std::string cameraStateFilePath = ghoul::lua::checkStringAndPop(L);
|
||||
|
||||
if (cameraStateFilePath.empty()) {
|
||||
return luaL_error(L, "filepath string is empty");
|
||||
}
|
||||
|
||||
OsEng.navigationHandler().saveCameraStateToFile(cameraStateFilePath);
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int resetCameraDirection(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::resetCameraDirection");
|
||||
|
||||
using ghoul::lua::luaTypeToString;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
}
|
||||
|
||||
OsEng.navigationHandler().resetCameraDirection();
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -25,15 +25,13 @@
|
||||
namespace openspace::luascriptfunctions {
|
||||
|
||||
int loadMission(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::loadMission");
|
||||
|
||||
std::string missionFileName = luaL_checkstring(L, -1);
|
||||
std::string missionFileName = ghoul::lua::checkStringAndPop(L);
|
||||
if (missionFileName.empty()) {
|
||||
return luaL_error(L, "Filepath is empty");
|
||||
}
|
||||
|
||||
std::string name = MissionManager::ref().loadMission(absPath(missionFileName));
|
||||
lua_pushstring(L, name.c_str());
|
||||
|
||||
@@ -42,14 +40,11 @@ int loadMission(lua_State* L) {
|
||||
}
|
||||
|
||||
int unloadMission(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::unloadMission");
|
||||
|
||||
std::string missionName = luaL_checkstring(L, -1);
|
||||
std::string missionName = ghoul::lua::checkStringAndPop(L);
|
||||
if (missionName.empty()) {
|
||||
return luaL_error(L, "Missing name is empty");
|
||||
return luaL_error(L, "Mission name is empty");
|
||||
}
|
||||
|
||||
if (!MissionManager::ref().hasMission(missionName)) {
|
||||
@@ -63,16 +58,13 @@ int unloadMission(lua_State* L) {
|
||||
}
|
||||
|
||||
int hasMission(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::hasMission");
|
||||
|
||||
std::string missionName = luaL_checkstring(L, -1);
|
||||
std::string missionName = ghoul::lua::checkStringAndPop(L);
|
||||
if (missionName.empty()) {
|
||||
return luaL_error(L, "Missing name is empty");
|
||||
}
|
||||
|
||||
|
||||
bool hasMission = MissionManager::ref().hasMission(missionName);
|
||||
|
||||
lua_pushboolean(L, hasMission);
|
||||
@@ -82,15 +74,13 @@ int hasMission(lua_State* L) {
|
||||
}
|
||||
|
||||
int setCurrentMission(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::setCurrentMission");
|
||||
|
||||
std::string missionName = luaL_checkstring(L, -1);
|
||||
std::string missionName = ghoul::lua::checkStringAndPop(L);
|
||||
if (missionName.empty()) {
|
||||
return luaL_error(L, "Mission name is empty");
|
||||
}
|
||||
|
||||
MissionManager::ref().setCurrentMission(missionName);
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
|
||||
@@ -82,7 +82,6 @@ using SocketResultType = size_t;
|
||||
#include <openspace/interaction/navigationhandler.h>
|
||||
#include <openspace/interaction/keyframenavigator.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/scripting/script_helper.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/timemanager.h>
|
||||
|
||||
|
||||
@@ -25,8 +25,7 @@
|
||||
namespace openspace::luascriptfunctions {
|
||||
|
||||
int connect(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("connect", L, 0, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::connect");
|
||||
|
||||
if (OsEng.windowWrapper().isMaster()) {
|
||||
OsEng.parallelConnection().clientConnect();
|
||||
@@ -37,8 +36,7 @@ int connect(lua_State* L) {
|
||||
}
|
||||
|
||||
int disconnect(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("disconnect", L, 0, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::disconnect");
|
||||
|
||||
if (OsEng.windowWrapper().isMaster()) {
|
||||
OsEng.parallelConnection().signalDisconnect();
|
||||
@@ -49,8 +47,7 @@ int disconnect(lua_State* L) {
|
||||
}
|
||||
|
||||
int requestHostship(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("requestHostship", L, 0, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::requestHostship");
|
||||
|
||||
if (OsEng.windowWrapper().isMaster()) {
|
||||
OsEng.parallelConnection().requestHostship();
|
||||
@@ -61,8 +58,7 @@ int requestHostship(lua_State* L) {
|
||||
}
|
||||
|
||||
int resignHostship(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("resignHostship", L, 0, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::resignHostship");
|
||||
|
||||
if (OsEng.windowWrapper().isMaster()) {
|
||||
OsEng.parallelConnection().resignHostship();
|
||||
|
||||
@@ -33,10 +33,7 @@ namespace openspace::luascriptfunctions {
|
||||
* addDashboardItem(table):
|
||||
*/
|
||||
int addDashboardItem(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::addDashboardItem");
|
||||
|
||||
int type = lua_type(L, -1);
|
||||
if (type == LUA_TTABLE) {
|
||||
@@ -66,10 +63,7 @@ int addDashboardItem(lua_State* L) {
|
||||
* removeDashboardItems():
|
||||
*/
|
||||
int removeDashboardItems(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments > 1) {
|
||||
return luaL_error(L, "Expected %i or %i arguments, got %i", 0, 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::removeDashboardItems");
|
||||
|
||||
OsEng.dashboard().removeDashboardItems();
|
||||
|
||||
|
||||
@@ -30,10 +30,7 @@ namespace openspace::luascriptfunctions {
|
||||
* Set renderer
|
||||
*/
|
||||
int setRenderer(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::setRenderer");
|
||||
|
||||
const int type = lua_type(L, -1);
|
||||
if (type != LUA_TSTRING) {
|
||||
@@ -52,10 +49,7 @@ int setRenderer(lua_State* L) {
|
||||
* Toggle a global fade over (float) seconds
|
||||
*/
|
||||
int toggleFade(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::toggleFade");
|
||||
|
||||
double t = luaL_checknumber(L, -1);
|
||||
|
||||
@@ -74,10 +68,7 @@ int toggleFade(lua_State* L) {
|
||||
* start a global fadein over (float) seconds
|
||||
*/
|
||||
int fadeIn(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::fadeIn");
|
||||
|
||||
double t = luaL_checknumber(L, -1);
|
||||
|
||||
@@ -92,10 +83,7 @@ int fadeIn(lua_State* L) {
|
||||
* start a global fadeout over (float) seconds
|
||||
*/
|
||||
int fadeOut(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::fadeOut");
|
||||
|
||||
double t = luaL_checknumber(L, -1);
|
||||
|
||||
@@ -106,12 +94,9 @@ int fadeOut(lua_State* L) {
|
||||
}
|
||||
|
||||
int addScreenSpaceRenderable(lua_State* L) {
|
||||
using ghoul::lua::errorLocation;
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::addScreenSpaceRenderable");
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
using ghoul::lua::errorLocation;
|
||||
|
||||
ghoul::Dictionary d;
|
||||
try {
|
||||
@@ -132,14 +117,11 @@ int addScreenSpaceRenderable(lua_State* L) {
|
||||
}
|
||||
|
||||
int removeScreenSpaceRenderable(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::removeScreenSpaceRenderable");
|
||||
|
||||
using ghoul::lua::errorLocation;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
|
||||
std::string name = luaL_checkstring(L, -1);
|
||||
std::string name = ghoul::lua::checkStringAndPop(L);
|
||||
|
||||
std::shared_ptr<ScreenSpaceRenderable> s = OsEng.renderEngine().screenSpaceRenderable(
|
||||
name
|
||||
|
||||
+23
-27
@@ -25,7 +25,6 @@
|
||||
#include <openspace/scene/assetloader.h>
|
||||
|
||||
#include <openspace/scene/asset.h>
|
||||
#include <openspace/scripting/script_helper.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/lua/luastate.h>
|
||||
@@ -389,39 +388,43 @@ std::shared_ptr<Asset> AssetLoader::getAsset(std::string name) {
|
||||
}
|
||||
|
||||
int AssetLoader::onInitializeLua(Asset* asset) {
|
||||
int nArguments = lua_gettop(*_luaState);
|
||||
SCRIPT_CHECK_ARGUMENTS("onInitialize", *_luaState, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(*_luaState, 1, "lua::onInitialize");
|
||||
|
||||
int referenceIndex = luaL_ref(*_luaState, LUA_REGISTRYINDEX);
|
||||
_onInitializationFunctionRefs[asset].push_back(referenceIndex);
|
||||
|
||||
lua_settop(*_luaState, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AssetLoader::onDeinitializeLua(Asset* asset) {
|
||||
int nArguments = lua_gettop(*_luaState);
|
||||
SCRIPT_CHECK_ARGUMENTS("onDeinitialize", *_luaState, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(*_luaState, 1, "lua::onDeinitialize");
|
||||
|
||||
int referenceIndex = luaL_ref(*_luaState, LUA_REGISTRYINDEX);
|
||||
_onDeinitializationFunctionRefs[asset].push_back(referenceIndex);
|
||||
|
||||
lua_settop(*_luaState, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AssetLoader::onInitializeDependencyLua(Asset* dependant, Asset* dependency) {
|
||||
int nArguments = lua_gettop(*_luaState);
|
||||
SCRIPT_CHECK_ARGUMENTS("onInitialize", *_luaState, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(*_luaState, 1, "lua::onInitializeDependency");
|
||||
|
||||
int referenceIndex = luaL_ref(*_luaState, LUA_REGISTRYINDEX);
|
||||
_onDependencyInitializationFunctionRefs[dependant][dependency]
|
||||
.push_back(referenceIndex);
|
||||
|
||||
lua_settop(*_luaState, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AssetLoader::onDeinitializeDependencyLua(Asset* dependant, Asset* dependency) {
|
||||
int nArguments = lua_gettop(*_luaState);
|
||||
SCRIPT_CHECK_ARGUMENTS("onDeinitialize", *_luaState, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(*_luaState, 1, "lua::onDeinitializeDependency");
|
||||
|
||||
int referenceIndex = luaL_ref(*_luaState, LUA_REGISTRYINDEX);
|
||||
_onDependencyDeinitializationFunctionRefs[dependant][dependency]
|
||||
.push_back(referenceIndex);
|
||||
|
||||
lua_settop(*_luaState, 0);
|
||||
return 0;
|
||||
}
|
||||
@@ -496,7 +499,7 @@ void AssetLoader::callOnInitialize(Asset* asset) {
|
||||
if (lua_pcall(*_luaState, 0, 0, 0) != LUA_OK) {
|
||||
throw ghoul::lua::LuaRuntimeException(
|
||||
"When initializing " + asset->assetFilePath() + ": " +
|
||||
luaL_checkstring(*_luaState, -1)
|
||||
ghoul::lua::checkStringAndPop(*_luaState)
|
||||
);
|
||||
}
|
||||
// Clean up lua stack, in case the pcall left anything there.
|
||||
@@ -511,7 +514,7 @@ void AssetLoader::callOnDeinitialize(Asset * asset) {
|
||||
if (lua_pcall(*_luaState, 0, 0, 0) != LUA_OK) {
|
||||
throw ghoul::lua::LuaRuntimeException(
|
||||
"When deinitializing " + asset->assetFilePath() + ": " +
|
||||
luaL_checkstring(*_luaState, -1)
|
||||
ghoul::lua::checkStringAndPop(*_luaState)
|
||||
);
|
||||
}
|
||||
// Clean up lua stack, in case the pcall left anything there.
|
||||
@@ -525,7 +528,7 @@ void AssetLoader::callOnDependencyInitialize(Asset* asset, Asset* dependant) {
|
||||
if (lua_pcall(*_luaState, 0, 0, 0) != LUA_OK) {
|
||||
throw ghoul::lua::LuaRuntimeException(
|
||||
"When initializing dependency " + dependant->assetFilePath() + " -> " +
|
||||
asset->assetFilePath() + ": " + luaL_checkstring(*_luaState, -1)
|
||||
asset->assetFilePath() + ": " + ghoul::lua::checkStringAndPop(*_luaState)
|
||||
);
|
||||
}
|
||||
// Clean up lua stack, in case the pcall left anything there.
|
||||
@@ -543,7 +546,7 @@ void AssetLoader::callOnDependencyDeinitialize(Asset* asset, Asset* dependant) {
|
||||
if (lua_pcall(*_luaState, 0, 0, 0) != LUA_OK) {
|
||||
throw ghoul::lua::LuaRuntimeException(
|
||||
"When deinitializing dependency " + dependant->assetFilePath() + " -> " +
|
||||
asset->assetFilePath() + ": " + luaL_checkstring(*_luaState, -1)
|
||||
asset->assetFilePath() + ": " + ghoul::lua::checkStringAndPop(*_luaState)
|
||||
);
|
||||
}
|
||||
// Clean up lua stack, in case the pcall left anything there.
|
||||
@@ -552,13 +555,11 @@ void AssetLoader::callOnDependencyDeinitialize(Asset* asset, Asset* dependant) {
|
||||
}
|
||||
|
||||
int AssetLoader::localResourceLua(Asset* asset) {
|
||||
int nArguments = lua_gettop(*_luaState);
|
||||
SCRIPT_CHECK_ARGUMENTS("localResource", *_luaState, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(*_luaState, 1, "lua::localResourceLua");
|
||||
|
||||
std::string resourceName = luaL_checkstring(*_luaState, -1);
|
||||
std::string resourceName = ghoul::lua::checkStringAndPop(*_luaState);
|
||||
std::string resolved = asset->resolveLocalResource(resourceName);
|
||||
|
||||
lua_settop(*_luaState, 0);
|
||||
lua_pushstring(*_luaState, resolved.c_str());
|
||||
|
||||
ghoul_assert(lua_gettop(*_luaState) == 1, "Incorrect number of items left on stack");
|
||||
@@ -566,8 +567,7 @@ int AssetLoader::localResourceLua(Asset* asset) {
|
||||
}
|
||||
|
||||
int AssetLoader::syncedResourceLua(Asset* asset) {
|
||||
int nArguments = lua_gettop(*_luaState);
|
||||
SCRIPT_CHECK_ARGUMENTS("syncedResource", *_luaState, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(*_luaState, 1, "lua::syncedResourceLua");
|
||||
|
||||
ghoul::Dictionary d;
|
||||
ghoul::lua::luaDictionaryFromState(*_luaState, d);
|
||||
@@ -608,8 +608,7 @@ void AssetLoader::setCurrentAsset(std::shared_ptr<Asset> asset) {
|
||||
}
|
||||
|
||||
int AssetLoader::requireLua(Asset* dependant) {
|
||||
int nArguments = lua_gettop(*_luaState);
|
||||
SCRIPT_CHECK_ARGUMENTS("require", *_luaState, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(*_luaState, 1, "lua::require");
|
||||
|
||||
std::string assetName = luaL_checkstring(*_luaState, 1);
|
||||
lua_settop(*_luaState, 0);
|
||||
@@ -647,8 +646,7 @@ int AssetLoader::requireLua(Asset* dependant) {
|
||||
}
|
||||
|
||||
int AssetLoader::requestLua(Asset* parent) {
|
||||
int nArguments = lua_gettop(*_luaState);
|
||||
SCRIPT_CHECK_ARGUMENTS("request", *_luaState, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(*_luaState, 1, "lua::request");
|
||||
|
||||
std::string assetName = luaL_checkstring(*_luaState, 1);
|
||||
lua_settop(*_luaState, 0);
|
||||
@@ -674,8 +672,7 @@ int AssetLoader::requestLua(Asset* parent) {
|
||||
}
|
||||
|
||||
int AssetLoader::existsLua(Asset* asset) {
|
||||
int nArguments = lua_gettop(*_luaState);
|
||||
SCRIPT_CHECK_ARGUMENTS("exists", *_luaState, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(*_luaState, 1, "lua::exists");
|
||||
|
||||
std::string assetName = luaL_checkstring(*_luaState, 1);
|
||||
|
||||
@@ -689,8 +686,7 @@ int AssetLoader::existsLua(Asset* asset) {
|
||||
}
|
||||
|
||||
int AssetLoader::exportAssetLua(Asset* asset) {
|
||||
int nArguments = lua_gettop(*_luaState);
|
||||
SCRIPT_CHECK_ARGUMENTS("exportAsset", *_luaState, 2, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(*_luaState, 2, "lua::exportAsset");
|
||||
|
||||
std::string exportName = luaL_checkstring(*_luaState, 1);
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
|
||||
#include <openspace/scene/assetmanager.h>
|
||||
|
||||
#include <openspace/scripting/script_helper.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/filesystem/file.h>
|
||||
#include <ghoul/misc/exception.h>
|
||||
|
||||
@@ -25,34 +25,39 @@
|
||||
namespace openspace::luascriptfunctions::asset {
|
||||
|
||||
int add(lua_State* state) {
|
||||
AssetManager *assetManager =
|
||||
ghoul::lua::checkArgumentsAndThrow(state, 1, "lua::add");
|
||||
|
||||
AssetManager* assetManager =
|
||||
reinterpret_cast<AssetManager*>(lua_touserdata(state, lua_upvalueindex(1)));
|
||||
|
||||
int nArguments = lua_gettop(state);
|
||||
SCRIPT_CHECK_ARGUMENTS("add", state, 1, nArguments);
|
||||
std::string assetName = luaL_checkstring(state, -1);
|
||||
std::string assetName = ghoul::lua::checkStringAndPop(state);
|
||||
assetManager->add(assetName);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int remove(lua_State* state) {
|
||||
AssetManager *assetManager =
|
||||
ghoul::lua::checkArgumentsAndThrow(state, 1, "lua::remove");
|
||||
|
||||
|
||||
AssetManager* assetManager =
|
||||
reinterpret_cast<AssetManager*>(lua_touserdata(state, lua_upvalueindex(1)));
|
||||
|
||||
int nArguments = lua_gettop(state);
|
||||
SCRIPT_CHECK_ARGUMENTS("remove", state, 1, nArguments);
|
||||
std::string assetName = luaL_checkstring(state, -1);
|
||||
std::string assetName = ghoul::lua::checkStringAndPop(state);
|
||||
assetManager->remove(assetName);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int removeAll(lua_State* state) {
|
||||
AssetManager *assetManager =
|
||||
ghoul::lua::checkArgumentsAndThrow(state, 0, "lua::removeAll");
|
||||
|
||||
|
||||
AssetManager* assetManager =
|
||||
reinterpret_cast<AssetManager*>(lua_touserdata(state, lua_upvalueindex(1)));
|
||||
|
||||
int nArguments = lua_gettop(state);
|
||||
SCRIPT_CHECK_ARGUMENTS("removeAll", state, 0, nArguments);
|
||||
assetManager->removeAll();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/scripting/script_helper.h>
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
+10
-16
@@ -169,8 +169,7 @@ int property_setValueSingle(lua_State* L) {
|
||||
using ghoul::lua::errorLocation;
|
||||
using ghoul::lua::luaTypeToString;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("property_setValueSingle", L, 2, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 2, "lua::property_setValueSingle");
|
||||
|
||||
std::string uri = luaL_checkstring(L, -2);
|
||||
const int type = lua_type(L, -1);
|
||||
@@ -226,8 +225,8 @@ int property_setValue(lua_State* L) {
|
||||
using ghoul::lua::errorLocation;
|
||||
using ghoul::lua::luaTypeToString;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("property_setGroup", L, 2, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 2, "lua::property_setGroup");
|
||||
|
||||
std::string regex = luaL_checkstring(L, -2);
|
||||
std::string groupName;
|
||||
|
||||
@@ -271,8 +270,8 @@ int property_setValueRegex(lua_State* L) {
|
||||
using ghoul::lua::errorLocation;
|
||||
using ghoul::lua::luaTypeToString;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("property_setValueRegex<", L, 2, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 2, "lua::property_setValueRegex");
|
||||
|
||||
std::string regex = luaL_checkstring(L, -2);
|
||||
std::string groupName;
|
||||
|
||||
@@ -309,8 +308,7 @@ int property_getValue(lua_State* L) {
|
||||
static const std::string _loggerCat = "property_getValue";
|
||||
using ghoul::lua::errorLocation;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("property_getValue", L, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::property_getValue");
|
||||
|
||||
std::string uri = luaL_checkstring(L, -1);
|
||||
lua_settop(L, 0);
|
||||
@@ -338,8 +336,7 @@ int property_getValue(lua_State* L) {
|
||||
* be passed to the setPropertyValue method.
|
||||
*/
|
||||
int loadScene(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("loadScene", L, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::loadScene");
|
||||
|
||||
std::string sceneFile = luaL_checkstring(L, -1);
|
||||
OsEng.scheduleLoadSingleAsset(sceneFile);
|
||||
@@ -351,8 +348,7 @@ int loadScene(lua_State* L) {
|
||||
int addSceneGraphNode(lua_State* L) {
|
||||
using ghoul::lua::errorLocation;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("addSceneGraphNode", L, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::addSceneGraphNode");
|
||||
|
||||
ghoul::Dictionary d;
|
||||
try {
|
||||
@@ -391,8 +387,7 @@ int addSceneGraphNode(lua_State* L) {
|
||||
int removeSceneGraphNode(lua_State* L) {
|
||||
using ghoul::lua::errorLocation;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("removeSceneGraphNode", L, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::removeSceneGraphNode");
|
||||
|
||||
std::string nodeName = luaL_checkstring(L, -1);
|
||||
SceneGraphNode* node = OsEng.renderEngine().scene()->sceneGraphNode(nodeName);
|
||||
@@ -421,8 +416,7 @@ int removeSceneGraphNode(lua_State* L) {
|
||||
|
||||
|
||||
int hasSceneGraphNode(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("hasSceneGraphNode", L, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::hasSceneGraphNode");
|
||||
|
||||
std::string nodeName = luaL_checkstring(L, -1);
|
||||
SceneGraphNode* node = OsEng.renderEngine().scene()->sceneGraphNode(nodeName);
|
||||
|
||||
@@ -31,10 +31,7 @@ namespace {
|
||||
// Defining a common walk function that works off a pointer-to-member function
|
||||
template <typename Func>
|
||||
int walkCommon(lua_State* L, Func func) {
|
||||
const int nArguments = lua_gettop(L);
|
||||
if (nArguments < 1 || nArguments > 3) {
|
||||
return luaL_error(L, "Expected %i-%i arguments, got %i", 1, 3, nArguments);
|
||||
}
|
||||
int nArguments = ghoul::lua::checkArgumentsAndThrow(L, { 1, 3 }, "lua::walkCommon");
|
||||
|
||||
std::vector<std::string> result;
|
||||
if (nArguments == 1) {
|
||||
@@ -87,13 +84,9 @@ int walkCommon(lua_State* L, Func func) {
|
||||
} // namespace
|
||||
|
||||
int printInternal(ghoul::logging::LogLevel level, lua_State* L) {
|
||||
using ghoul::lua::luaTypeToString;
|
||||
const std::string _loggerCat = "print";
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::printInternal");
|
||||
|
||||
const int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
using ghoul::lua::luaTypeToString;
|
||||
|
||||
const int type = lua_type(L, -1);
|
||||
switch (type) {
|
||||
@@ -195,13 +188,9 @@ int printFatal(lua_State* L) {
|
||||
* tokens and returns the absolute path.
|
||||
*/
|
||||
int absolutePath(lua_State* L) {
|
||||
const int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %d arguments, got %d", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::absolutePath");
|
||||
|
||||
std::string path = luaL_checkstring(L, -1);
|
||||
lua_settop(L, 0);
|
||||
std::string path = ghoul::lua::checkStringAndPop(L);
|
||||
|
||||
path = absPath(path);
|
||||
//path = FileSys.convertPathSeparator(path, '/');
|
||||
@@ -216,19 +205,17 @@ int absolutePath(lua_State* L) {
|
||||
* argument. If the path token already exists, it will be silently overridden.
|
||||
*/
|
||||
int setPathToken(lua_State* L) {
|
||||
const int nArguments = lua_gettop(L);
|
||||
if (nArguments != 2) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 2, "lua::setPathToken");
|
||||
|
||||
const std::string path = ghoul::lua::checkStringAndPop(L);
|
||||
const std::string pathToken = ghoul::lua::checkStringAndPop(L);
|
||||
|
||||
const std::string path = luaL_checkstring(L, -1);
|
||||
const std::string pathToken = luaL_checkstring(L, -2);
|
||||
lua_settop(L, 0);
|
||||
FileSys.registerPathToken(
|
||||
pathToken,
|
||||
path,
|
||||
ghoul::filesystem::FileSystem::Override::Yes
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -238,16 +225,13 @@ int setPathToken(lua_State* L) {
|
||||
* Checks whether the provided file exists
|
||||
*/
|
||||
int fileExists(lua_State* L) {
|
||||
const int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::fileExists");
|
||||
|
||||
const std::string file = luaL_checkstring(L, -1);
|
||||
const std::string file = ghoul::lua::checkStringAndPop(L);
|
||||
const bool e = FileSys.fileExists(absPath(file));
|
||||
|
||||
lua_settop(L, 0);
|
||||
lua_pushboolean(L, (e ? 1 : 0));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -257,15 +241,12 @@ int fileExists(lua_State* L) {
|
||||
* Checks whether the provided file exists
|
||||
*/
|
||||
int directoryExists(lua_State* L) {
|
||||
const int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::directoryExists");
|
||||
|
||||
const std::string file = luaL_checkstring(L, -1);
|
||||
|
||||
const std::string file = ghoul::lua::checkStringAndPop(L);
|
||||
const bool e = FileSys.directoryExists(absPath(file));
|
||||
|
||||
lua_settop(L, 0);
|
||||
lua_pushboolean(L, (e ? 1 : 0));
|
||||
return 1;
|
||||
}
|
||||
@@ -319,16 +300,13 @@ int walkDirectoryFolder(lua_State* L) {
|
||||
* 'C:\\OpenSpace\\foobar'."
|
||||
*/
|
||||
int directoryForPath(lua_State* L) {
|
||||
const int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::directoryForPath");
|
||||
|
||||
const std::string file = luaL_checkstring(L, -1);
|
||||
const std::string file = ghoul::lua::checkStringAndPop(L);
|
||||
const std::string path = ghoul::filesystem::File(file).directoryName();
|
||||
|
||||
lua_settop(L, 0);
|
||||
lua_pushstring(L, path.c_str());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,12 +25,9 @@
|
||||
namespace openspace::luascriptfunctions {
|
||||
|
||||
int loadFile(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::loadFile");
|
||||
|
||||
std::string missionFileName = luaL_checkstring(L, -1);
|
||||
std::string missionFileName = ghoul::lua::checkStringAndPop(L);
|
||||
if (missionFileName.empty()) {
|
||||
return luaL_error(L, "filepath string is empty");
|
||||
}
|
||||
@@ -44,7 +41,12 @@ int loadFile(lua_State* L) {
|
||||
}
|
||||
|
||||
int loadScheduledScript(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
int nArguments = ghoul::lua::checkArgumentsAndThrow(
|
||||
L,
|
||||
{ 2, 4 },
|
||||
"lua::loadScheduledScript"
|
||||
);
|
||||
|
||||
if (nArguments == 2) {
|
||||
OsEng.scriptScheduler().loadScripts({
|
||||
{
|
||||
@@ -81,19 +83,13 @@ int loadScheduledScript(lua_State* L) {
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
return luaL_error(L, "Expected %i-%i arguments, got %i", 2, 4, nArguments);
|
||||
}
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int clear(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::clear");
|
||||
|
||||
OsEng.scriptScheduler().clearSchedule();
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include <openspace/scripting/systemcapabilitiesbinding.h>
|
||||
|
||||
#include <openspace/scripting/script_helper.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
@@ -84,10 +83,9 @@ int extensions(lua_State* L) {
|
||||
namespace luascripting::opengl {
|
||||
|
||||
int hasOpenGLVersion(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("hasVersion", L, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::hasOpenGLVersion");
|
||||
|
||||
std::vector<std::string> v = ghoul::tokenizeString(luaL_checkstring(L, -1));
|
||||
std::vector<std::string> v = ghoul::tokenizeString(ghoul::lua::checkStringAndPop(L));
|
||||
if (v.size() != 2 && v.size() != 3) {
|
||||
LERRORC("hasVersion", ghoul::lua::errorLocation(L) << "Malformed version string");
|
||||
return 0;
|
||||
@@ -144,10 +142,9 @@ int extensions(lua_State* L) {
|
||||
}
|
||||
|
||||
int isExtensionSupported(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("hasVersion", L, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::hasExtension");
|
||||
|
||||
std::string extension = luaL_checkstring(L, -1);
|
||||
std::string extension = ghoul::lua::checkStringAndPop(L);
|
||||
|
||||
lua_pushboolean(L, OpenGLCap.isExtensionSupported(extension));
|
||||
return 1;
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/scripting/script_helper.h>
|
||||
|
||||
namespace openspace::luascriptfunctions {
|
||||
|
||||
/**
|
||||
@@ -34,8 +32,7 @@ namespace openspace::luascriptfunctions {
|
||||
*/
|
||||
|
||||
int loadKernel(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("loadKernel", L, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::loadKernel");
|
||||
|
||||
bool isString = (lua_isstring(L, -1) == 1);
|
||||
if (!isString) {
|
||||
@@ -43,13 +40,12 @@ int loadKernel(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string argument = lua_tostring(L, -1);
|
||||
std::string argument = ghoul::lua::checkStringAndPop(L);
|
||||
if (!FileSys.fileExists(argument)) {
|
||||
return luaL_error(L, "Kernel file '%s' did not exist", argument.c_str());
|
||||
}
|
||||
unsigned int result = SpiceManager::ref().loadKernel(argument);
|
||||
|
||||
lua_settop(L, 0);
|
||||
lua_pushnumber(L, result);
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 1, "Incorrect number of items left on stack");
|
||||
@@ -62,8 +58,7 @@ int loadKernel(lua_State* L) {
|
||||
* automatically resolved.
|
||||
*/
|
||||
int unloadKernel(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
SCRIPT_CHECK_ARGUMENTS("unloadKernel", L, 1, nArguments);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::loadKernel");
|
||||
|
||||
bool isString = (lua_isstring(L, -1) == 1);
|
||||
bool isNumber = (lua_isnumber(L, -1) == 1);
|
||||
|
||||
@@ -78,12 +78,10 @@ int time_deltaTime(lua_State* L) {
|
||||
* Toggles a pause functionm i.e. setting the delta time to 0 and restoring it afterwards
|
||||
*/
|
||||
int time_togglePause(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::time_togglePause");
|
||||
|
||||
OsEng.timeManager().time().togglePause();
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
@@ -94,10 +92,7 @@ int time_togglePause(lua_State* L) {
|
||||
* Toggles a pause functionm i.e. setting the delta time to 0 and restoring it afterwards
|
||||
*/
|
||||
int time_setPause(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::time_setPause");
|
||||
|
||||
bool pause = lua_toboolean(L, -1) == 1;
|
||||
OsEng.timeManager().time().setPause(pause);
|
||||
|
||||
Reference in New Issue
Block a user