luaL_error use replaced with c++ exceptions
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "../../../graphics/ui/elements/InventoryView.hpp"
|
||||
#include "../../../items/Inventories.hpp"
|
||||
#include "../../../logic/BlocksController.hpp"
|
||||
#include "../../../util/stringutil.hpp"
|
||||
#include "../../../voxels/Block.hpp"
|
||||
#include "../../../voxels/Chunks.hpp"
|
||||
#include "../../../voxels/voxel.hpp"
|
||||
@@ -45,17 +46,18 @@ static int l_hud_open_block(lua_State* L) {
|
||||
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox == nullptr) {
|
||||
luaL_error(L, "block does not exists at %d %d %d", x, y, z);
|
||||
throw std::runtime_error("block does not exists at "+
|
||||
std::to_string(x) + " " + std::to_string(y) + " " + std::to_string(z)
|
||||
);
|
||||
}
|
||||
auto def = scripting::content->getIndices()->getBlockDef(vox->id);
|
||||
auto assets = scripting::engine->getAssets();
|
||||
auto layout = assets->getLayout(def->uiLayout);
|
||||
if (layout == nullptr) {
|
||||
luaL_error(L, "block '%s' has no ui layout", def->name.c_str());
|
||||
throw std::runtime_error("block '"+def->name+"' has no ui layout");
|
||||
}
|
||||
|
||||
auto id = scripting::blocks->createBlockInventory(x, y, z);
|
||||
|
||||
scripting::hud->openInventory(
|
||||
glm::ivec3(x, y, z), layout, scripting::level->inventories->get(id), playerInventory
|
||||
);
|
||||
@@ -72,7 +74,7 @@ static int l_hud_show_overlay(lua_State* L) {
|
||||
auto assets = scripting::engine->getAssets();
|
||||
auto layout = assets->getLayout(name);
|
||||
if (layout == nullptr) {
|
||||
luaL_error(L, "there is no ui layout '%s'", name);
|
||||
throw std::runtime_error("there is no ui layout "+util::quote(name));
|
||||
}
|
||||
scripting::hud->showOverlay(layout, playerInventory);
|
||||
return 0;
|
||||
@@ -82,7 +84,7 @@ static UiDocument* require_layout(lua_State* L, const char* name) {
|
||||
auto assets = scripting::engine->getAssets();
|
||||
auto layout = assets->getLayout(name);
|
||||
if (layout == nullptr) {
|
||||
luaL_error(L, "layout '%s' is not found", name);
|
||||
throw std::runtime_error("layout '"+std::string(name)+"' is not found");
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user