Changed the naming conventions (read more)

I've changed some naming concentions in the lua APIs. I've also made a few
other tweaks, like region_pager_api.cpp delegating to the passed
RegionPager object. This won't explicitly run, becuase there's still a few
more changes needed.
This commit is contained in:
Kayne Ruse
2014-06-23 03:45:30 +10:00
parent e19b6fbc23
commit 64baa63d12
12 changed files with 98 additions and 133 deletions
+22 -22
View File
@@ -64,43 +64,43 @@ static int getDepth(lua_State* L) {
return 1;
}
static int load(lua_State* L) {
//TODO: fill this
static int onLoad(lua_State* L) {
//TODO: onLoad()
lua_pushboolean(L, false);
return 1;
}
static int save(lua_State* L) {
//TODO: fill this
static int onSave(lua_State* L) {
//TODO: onSave()
return 0;
}
static int create(lua_State* L) {
//TODO: fill this
static int onCreate(lua_State* L) {
//TODO: onCreate()
return 0;
}
static int unload(lua_State* L) {
//TODO: fill this
static int onUnload(lua_State* L) {
//TODO: onUnload()
return 0;
}
static const luaL_Reg regionlib[] = {
{"settile",setTile},
{"gettile",getTile},
{"getx",getX},
{"gety",getY},
{"getwidth",getWidth},
{"getheight",getHeight},
{"getdepth",getDepth},
{"load",load},
{"save",save},
{"create",create},
{"unload",unload},
static const luaL_Reg regionLib[] = {
{"SetTile",setTile},
{"SetTile",getTile},
{"GetX",getX},
{"GetY",getY},
{"GetWidth",getWidth},
{"GetHeight",getHeight},
{"GetDepth",getDepth},
{"OnLoad",onLoad},
{"OnSave",onSave},
{"OnCreate",onCreate},
{"OnUnload",onUnload},
{nullptr, nullptr}
};
LUAMOD_API int luaopen_regionapi(lua_State* L) {
luaL_newlib(L, regionlib);
LUAMOD_API int openRegionAPI(lua_State* L) {
luaL_newlib(L, regionLib);
return 1;
}
+2 -2
View File
@@ -24,7 +24,7 @@
#include "lua/lua.hpp"
#define LUA_REGIONLIBNAME "region"
LUAMOD_API int luaopen_regionapi(lua_State* L);
#define TORTUGA_REGION_NAME "Region"
LUAMOD_API int openRegionAPI(lua_State* L);
#endif
@@ -19,7 +19,7 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "pager_api.hpp"
#include "region_pager_api.hpp"
#include "region_pager_lua.hpp"
#include "region.hpp"
@@ -27,6 +27,8 @@
#include <stdexcept>
#include <string>
//DOCS: These functions are just wrappers for the RegionPagerLua class
static int setTile(lua_State* L) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
int ret = pager->SetTile(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
@@ -63,94 +65,46 @@ static int getDirectory(lua_State* L) {
}
static int loadRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(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");
Region* region = pager->LoadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
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) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(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");
Region* region = pager->SaveRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
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 1;
}
static int createRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(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");
Region* region = pager->CreateRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
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 1;
}
static int unloadRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(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) ));
}
pager->UnloadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
return 0;
}
static const luaL_Reg pagerlib[] = {
{"settile", setTile},
{"gettile", getTile},
{"getregion", getRegion},
{"setdirectory", setDirectory},
{"getdirectory", getDirectory},
{"loadregion", loadRegion},
{"saveregion", saveRegion},
{"createregion", createRegion},
{"unloadregion", unloadRegion},
{"SetTile", setTile},
{"GetTile", getTile},
{"GetRegion", getRegion},
{"SetDirectory", setDirectory},
{"GetDirectory", getDirectory},
{"LoadRegion", loadRegion},
{"SaveRegion", saveRegion},
{"CreateRegion", createRegion},
{"UnloadRegion", unloadRegion},
{nullptr, nullptr}
};
LUAMOD_API int luaopen_pagerapi(lua_State* L) {
LUAMOD_API int openRegionPagerAPI(lua_State* L) {
luaL_newlib(L, pagerlib);
return 1;
}
@@ -24,7 +24,7 @@
#include "lua/lua.hpp"
#define LUA_PAGERLIBNAME "pager"
LUAMOD_API int luaopen_pagerapi(lua_State* L);
#define TORTUGA_REGION_PAGER_NAME "pager"
LUAMOD_API int openRegionPagerAPI(lua_State* L);
#endif
+10 -10
View File
@@ -32,8 +32,8 @@ Region* RegionPagerLua::LoadRegion(int x, int y) {
regionList.emplace_front(x, y);
//API hook
lua_getglobal(luaState, "region");
lua_getfield(luaState, -1, "load");
lua_getglobal(luaState, "Region");
lua_getfield(luaState, -1, "OnLoad");
lua_pushlightuserdata(luaState, &regionList.front());
lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 1, 0) != LUA_OK) {
@@ -54,8 +54,8 @@ Region* RegionPagerLua::SaveRegion(int x, int y) {
Region* ptr = FindRegion(x, y);
if (ptr) {
//API hook
lua_getglobal(luaState, "region");
lua_getfield(luaState, -1, "save");
lua_getglobal(luaState, "Region");
lua_getfield(luaState, -1, "OnSave");
lua_pushlightuserdata(luaState, ptr);
lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
@@ -75,8 +75,8 @@ Region* RegionPagerLua::CreateRegion(int x, int y) {
regionList.emplace_front(x, y);
//API hook
lua_getglobal(luaState, "region");
lua_getfield(luaState, -1, "create");
lua_getglobal(luaState, "Region");
lua_getfield(luaState, -1, "OnCreate");
lua_pushlightuserdata(luaState, &regionList.front());
//TODO: parameters
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
@@ -87,13 +87,13 @@ Region* RegionPagerLua::CreateRegion(int x, int y) {
}
void RegionPagerLua::UnloadRegion(int x, int y) {
lua_getglobal(luaState, "region");
lua_getglobal(luaState, "Region");
regionList.remove_if([&](Region& region) -> bool {
if (region.GetX() == x && region.GetY() == y) {
//API hook
lua_getfield(luaState, -1, "unload");
lua_getfield(luaState, -1, "OnUnload");
lua_pushlightuserdata(luaState, &region);
lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
@@ -109,11 +109,11 @@ void RegionPagerLua::UnloadRegion(int x, int y) {
}
void RegionPagerLua::UnloadAll() {
lua_getglobal(luaState, "region");
lua_getglobal(luaState, "Region");
for (auto& it : regionList) {
//API hook
lua_getfield(luaState, -1, "unload");
lua_getfield(luaState, -1, "OnUnload");
lua_pushlightuserdata(luaState, &it);
lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {