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_pager.hpp"
|
||||||
#include "region.hpp"
|
#include "region.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
static int setTile(lua_State* L) {
|
static int setTile(lua_State* L) {
|
||||||
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
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));
|
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);
|
lua_pushinteger(L, ret);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,6 @@ static int setTile(lua_State* L) {
|
|||||||
static int getTile(lua_State* L) {
|
static int getTile(lua_State* L) {
|
||||||
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
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));
|
int ret = pager->GetTile(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4));
|
||||||
lua_pop(L, 4);
|
|
||||||
lua_pushinteger(L, ret);
|
lua_pushinteger(L, ret);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -45,7 +44,6 @@ static int getTile(lua_State* L) {
|
|||||||
static int getRegion(lua_State* L) {
|
static int getRegion(lua_State* L) {
|
||||||
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
||||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||||
lua_pop(L, 3);
|
|
||||||
lua_pushlightuserdata(L, region);
|
lua_pushlightuserdata(L, region);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -53,7 +51,6 @@ static int getRegion(lua_State* L) {
|
|||||||
static int setDirectory(lua_State* L) {
|
static int setDirectory(lua_State* L) {
|
||||||
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
||||||
std::string s = pager->SetDirectory(lua_tostring(L, 2));
|
std::string s = pager->SetDirectory(lua_tostring(L, 2));
|
||||||
lua_pop(L, 2);
|
|
||||||
lua_pushstring(L, s.c_str());
|
lua_pushstring(L, s.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -61,28 +58,82 @@ static int setDirectory(lua_State* L) {
|
|||||||
static int getDirectory(lua_State* L) {
|
static int getDirectory(lua_State* L) {
|
||||||
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
RegionPager* pager = reinterpret_cast<RegionPager*>(lua_touserdata(L, 1));
|
||||||
std::string s = pager->GetDirectory();
|
std::string s = pager->GetDirectory();
|
||||||
lua_pop(L, 1);
|
|
||||||
lua_pushstring(L, s.c_str());
|
lua_pushstring(L, s.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int loadRegion(lua_State* L) {
|
static int loadRegion(lua_State* L) {
|
||||||
//TODO: fill this
|
//get the parameters
|
||||||
return 0;
|
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) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int createRegion(lua_State* L) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int unloadRegion(lua_State* L) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
static int setTile(lua_State* L) {
|
static int setTile(lua_State* L) {
|
||||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
||||||
int ret = region->SetTile(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_tointeger(L, 4)-1, lua_tointeger(L, 5));
|
int ret = region->SetTile(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_tointeger(L, 4)-1, lua_tointeger(L, 5));
|
||||||
lua_pop(L, 5);
|
|
||||||
lua_pushinteger(L, ret);
|
lua_pushinteger(L, ret);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -34,24 +33,19 @@ static int setTile(lua_State* L) {
|
|||||||
static int getTile(lua_State* L) {
|
static int getTile(lua_State* L) {
|
||||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
||||||
int ret = region->GetTile(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_tointeger(L, 4)-1);
|
int ret = region->GetTile(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_tointeger(L, 4)-1);
|
||||||
lua_pop(L, 4);
|
|
||||||
lua_pushinteger(L, ret);
|
lua_pushinteger(L, ret);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getX(lua_State* L) {
|
static int getX(lua_State* L) {
|
||||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
||||||
int ret = region->GetX();
|
lua_pushinteger(L, region->GetX());
|
||||||
lua_pop(L, 1);
|
|
||||||
lua_pushinteger(L, ret);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getY(lua_State* L) {
|
static int getY(lua_State* L) {
|
||||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
||||||
int ret = region->GetY();
|
lua_pushinteger(L, region->GetY());
|
||||||
lua_pop(L, 1);
|
|
||||||
lua_pushinteger(L, ret);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user