Expaneded the lua API for Regions
I've added lua hooks for both pager functor classes. Hopefully, I haven't missed any corner cases, because it took me a while to hunt everything down. One issue is that the map's save directory needs to be set in the Format class, but it'll do for now. I'll review this again when I've got more than one map running at one time. There should be enough here for a lua-driven map generator to be implemented, even if it's a bit rough. I think I'll test this out in the editor eventually, but getting the base branch's network map code going comes first. The current process is extremely convulted, so I need to document everything that I've done so far, including C++ and lua functions.
This commit is contained in:
@@ -21,7 +21,9 @@
|
||||
*/
|
||||
#include "map_file_format.hpp"
|
||||
|
||||
void DummyFormat::Load(Region** const ptr, int x, int y) {
|
||||
#include <stdexcept>
|
||||
|
||||
void DummyFormat::Load(Region** const ptr, int width, int height, int depth, int x, int y) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
@@ -44,4 +46,34 @@ void CompactFormat::Load(Region** const ptr, int x, int y) {
|
||||
void CompactFormat::Save(Region* const ptr) {
|
||||
//TODO
|
||||
}
|
||||
*/
|
||||
*/
|
||||
void LuaFormat::Load(Region** const ptr, int width, int height, int depth, int x, int y) {
|
||||
//something to load into
|
||||
(*ptr) = new Region(width, height, depth, x, y);
|
||||
|
||||
//API hook
|
||||
lua_getglobal(state, "Region");
|
||||
lua_getfield(state, -1, "Load");
|
||||
lua_pushlightuserdata(state, *ptr);
|
||||
lua_pushstring(state, saveDir.c_str());
|
||||
if (lua_pcall(state, 2, 1, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(state, -1) ));
|
||||
}
|
||||
if (lua_toboolean(state, -1) == false) {
|
||||
delete (*ptr);
|
||||
(*ptr) = nullptr;
|
||||
}
|
||||
lua_pop(state, 2);
|
||||
}
|
||||
|
||||
void LuaFormat::Save(Region* const ptr) {
|
||||
//API hook
|
||||
lua_getglobal(state, "Region");
|
||||
lua_getfield(state, -1, "Save");
|
||||
lua_pushlightuserdata(state, ptr);
|
||||
lua_pushstring(state, saveDir.c_str());
|
||||
if (lua_pcall(state, 2, 0, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(state, -1) ));
|
||||
}
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
Reference in New Issue
Block a user