Pager's heavyweight API methods call the Region's counterparts
This commit is contained in:
+61
-10
@@ -24,12 +24,12 @@
|
||||
#include "region_pager.hpp"
|
||||
#include "region.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
static int setTile(lua_State* L) {
|
||||
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
||||
int ret = pager->SetTile(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
|
||||
lua_pop(L, 5);
|
||||
lua_pushinteger(L, ret);
|
||||
return 1;
|
||||
}
|
||||
@@ -37,7 +37,6 @@ static int setTile(lua_State* L) {
|
||||
static int getTile(lua_State* L) {
|
||||
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
||||
int ret = pager->GetTile(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4));
|
||||
lua_pop(L, 4);
|
||||
lua_pushinteger(L, ret);
|
||||
return 1;
|
||||
}
|
||||
@@ -45,7 +44,6 @@ static int getTile(lua_State* L) {
|
||||
static int getRegion(lua_State* L) {
|
||||
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
lua_pop(L, 3);
|
||||
lua_pushlightuserdata(L, region);
|
||||
return 1;
|
||||
}
|
||||
@@ -53,7 +51,6 @@ static int getRegion(lua_State* L) {
|
||||
static int setDirectory(lua_State* L) {
|
||||
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
||||
std::string s = pager->SetDirectory(lua_tostring(L, 2));
|
||||
lua_pop(L, 2);
|
||||
lua_pushstring(L, s.c_str());
|
||||
return 1;
|
||||
}
|
||||
@@ -61,28 +58,82 @@ static int setDirectory(lua_State* L) {
|
||||
static int getDirectory(lua_State* L) {
|
||||
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
||||
std::string s = pager->GetDirectory();
|
||||
lua_pop(L, 1);
|
||||
lua_pushstring(L, s.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int loadRegion(lua_State* L) {
|
||||
//TODO: fill this
|
||||
return 0;
|
||||
//get the parameters
|
||||
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
std::string s = pager->GetDirectory();
|
||||
|
||||
//push the parameters
|
||||
lua_getglobal(L, "region");
|
||||
lua_getfield(L, -1, "load");
|
||||
lua_pushlightuserdata(L, region);
|
||||
lua_pushstring(L, s.c_str());
|
||||
|
||||
//call the method
|
||||
if (lua_pcall(L, 2, 1, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int saveRegion(lua_State* L) {
|
||||
//TODO: fill this
|
||||
//get the parameters
|
||||
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
std::string s = pager->GetDirectory();
|
||||
|
||||
//push the parameters
|
||||
lua_getglobal(L, "region");
|
||||
lua_getfield(L, -1, "save");
|
||||
lua_pushlightuserdata(L, region);
|
||||
lua_pushstring(L, s.c_str());
|
||||
|
||||
//call the method
|
||||
if (lua_pcall(L, 2, 0, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int createRegion(lua_State* L) {
|
||||
//TODO: fill this
|
||||
//get the parameters
|
||||
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
|
||||
//push the parameters
|
||||
lua_getglobal(L, "region");
|
||||
lua_getfield(L, -1, "create");
|
||||
lua_pushlightuserdata(L, region);
|
||||
//TODO: parameters
|
||||
|
||||
//call the method
|
||||
if (lua_pcall(L, 1, 0, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unloadRegion(lua_State* L) {
|
||||
//TODO: fill this
|
||||
//get the parameters
|
||||
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
std::string s = pager->GetDirectory();
|
||||
|
||||
//push the parameters
|
||||
lua_getglobal(L, "region");
|
||||
lua_getfield(L, -1, "unload");
|
||||
lua_pushlightuserdata(L, region);
|
||||
lua_pushstring(L, s.c_str());
|
||||
|
||||
//call the method
|
||||
if (lua_pcall(L, 2, 0, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user