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; return 1;
} }
static int load(lua_State* L) { static int onLoad(lua_State* L) {
//TODO: fill this //TODO: onLoad()
lua_pushboolean(L, false); lua_pushboolean(L, false);
return 1; return 1;
} }
static int save(lua_State* L) { static int onSave(lua_State* L) {
//TODO: fill this //TODO: onSave()
return 0; return 0;
} }
static int create(lua_State* L) { static int onCreate(lua_State* L) {
//TODO: fill this //TODO: onCreate()
return 0; return 0;
} }
static int unload(lua_State* L) { static int onUnload(lua_State* L) {
//TODO: fill this //TODO: onUnload()
return 0; return 0;
} }
static const luaL_Reg regionlib[] = { static const luaL_Reg regionLib[] = {
{"settile",setTile}, {"SetTile",setTile},
{"gettile",getTile}, {"SetTile",getTile},
{"getx",getX}, {"GetX",getX},
{"gety",getY}, {"GetY",getY},
{"getwidth",getWidth}, {"GetWidth",getWidth},
{"getheight",getHeight}, {"GetHeight",getHeight},
{"getdepth",getDepth}, {"GetDepth",getDepth},
{"load",load}, {"OnLoad",onLoad},
{"save",save}, {"OnSave",onSave},
{"create",create}, {"OnCreate",onCreate},
{"unload",unload}, {"OnUnload",onUnload},
{nullptr, nullptr} {nullptr, nullptr}
}; };
LUAMOD_API int luaopen_regionapi(lua_State* L) { LUAMOD_API int openRegionAPI(lua_State* L) {
luaL_newlib(L, regionlib); luaL_newlib(L, regionLib);
return 1; return 1;
} }
+2 -2
View File
@@ -24,7 +24,7 @@
#include "lua/lua.hpp" #include "lua/lua.hpp"
#define LUA_REGIONLIBNAME "region" #define TORTUGA_REGION_NAME "Region"
LUAMOD_API int luaopen_regionapi(lua_State* L); LUAMOD_API int openRegionAPI(lua_State* L);
#endif #endif
@@ -19,7 +19,7 @@
* 3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
* distribution. * distribution.
*/ */
#include "pager_api.hpp" #include "region_pager_api.hpp"
#include "region_pager_lua.hpp" #include "region_pager_lua.hpp"
#include "region.hpp" #include "region.hpp"
@@ -27,6 +27,8 @@
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
//DOCS: These functions are just wrappers for the RegionPagerLua class
static int setTile(lua_State* L) { static int setTile(lua_State* L) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1)); 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)); 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) { static int loadRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1)); RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3)); Region* region = pager->LoadRegion(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_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; return 1;
} }
static int saveRegion(lua_State* L) { static int saveRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1)); RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3)); Region* region = pager->SaveRegion(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_pushlightuserdata(L, region);
lua_pushstring(L, s.c_str()); return 1;
//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) { static int createRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1)); RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3)); Region* region = pager->CreateRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
//push the parameters
lua_getglobal(L, "region");
lua_getfield(L, -1, "create");
lua_pushlightuserdata(L, region); lua_pushlightuserdata(L, region);
//TODO: parameters return 1;
//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) { static int unloadRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1)); RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3)); pager->UnloadRegion(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;
} }
static const luaL_Reg pagerlib[] = { static const luaL_Reg pagerlib[] = {
{"settile", setTile}, {"SetTile", setTile},
{"gettile", getTile}, {"GetTile", getTile},
{"getregion", getRegion}, {"GetRegion", getRegion},
{"setdirectory", setDirectory}, {"SetDirectory", setDirectory},
{"getdirectory", getDirectory}, {"GetDirectory", getDirectory},
{"loadregion", loadRegion}, {"LoadRegion", loadRegion},
{"saveregion", saveRegion}, {"SaveRegion", saveRegion},
{"createregion", createRegion}, {"CreateRegion", createRegion},
{"unloadregion", unloadRegion}, {"UnloadRegion", unloadRegion},
{nullptr, nullptr} {nullptr, nullptr}
}; };
LUAMOD_API int luaopen_pagerapi(lua_State* L) { LUAMOD_API int openRegionPagerAPI(lua_State* L) {
luaL_newlib(L, pagerlib); luaL_newlib(L, pagerlib);
return 1; return 1;
} }
@@ -24,7 +24,7 @@
#include "lua/lua.hpp" #include "lua/lua.hpp"
#define LUA_PAGERLIBNAME "pager" #define TORTUGA_REGION_PAGER_NAME "pager"
LUAMOD_API int luaopen_pagerapi(lua_State* L); LUAMOD_API int openRegionPagerAPI(lua_State* L);
#endif #endif
+10 -10
View File
@@ -32,8 +32,8 @@ Region* RegionPagerLua::LoadRegion(int x, int y) {
regionList.emplace_front(x, y); regionList.emplace_front(x, y);
//API hook //API hook
lua_getglobal(luaState, "region"); lua_getglobal(luaState, "Region");
lua_getfield(luaState, -1, "load"); lua_getfield(luaState, -1, "OnLoad");
lua_pushlightuserdata(luaState, &regionList.front()); lua_pushlightuserdata(luaState, &regionList.front());
lua_pushstring(luaState, directory.c_str()); lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 1, 0) != LUA_OK) { 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); Region* ptr = FindRegion(x, y);
if (ptr) { if (ptr) {
//API hook //API hook
lua_getglobal(luaState, "region"); lua_getglobal(luaState, "Region");
lua_getfield(luaState, -1, "save"); lua_getfield(luaState, -1, "OnSave");
lua_pushlightuserdata(luaState, ptr); lua_pushlightuserdata(luaState, ptr);
lua_pushstring(luaState, directory.c_str()); lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) { 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); regionList.emplace_front(x, y);
//API hook //API hook
lua_getglobal(luaState, "region"); lua_getglobal(luaState, "Region");
lua_getfield(luaState, -1, "create"); lua_getfield(luaState, -1, "OnCreate");
lua_pushlightuserdata(luaState, &regionList.front()); lua_pushlightuserdata(luaState, &regionList.front());
//TODO: parameters //TODO: parameters
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) { 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) { void RegionPagerLua::UnloadRegion(int x, int y) {
lua_getglobal(luaState, "region"); lua_getglobal(luaState, "Region");
regionList.remove_if([&](Region& region) -> bool { regionList.remove_if([&](Region& region) -> bool {
if (region.GetX() == x && region.GetY() == y) { if (region.GetX() == x && region.GetY() == y) {
//API hook //API hook
lua_getfield(luaState, -1, "unload"); lua_getfield(luaState, -1, "OnUnload");
lua_pushlightuserdata(luaState, &region); lua_pushlightuserdata(luaState, &region);
lua_pushstring(luaState, directory.c_str()); lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) { if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
@@ -109,11 +109,11 @@ void RegionPagerLua::UnloadRegion(int x, int y) {
} }
void RegionPagerLua::UnloadAll() { void RegionPagerLua::UnloadAll() {
lua_getglobal(luaState, "region"); lua_getglobal(luaState, "Region");
for (auto& it : regionList) { for (auto& it : regionList) {
//API hook //API hook
lua_getfield(luaState, -1, "unload"); lua_getfield(luaState, -1, "OnUnload");
lua_pushlightuserdata(luaState, &it); lua_pushlightuserdata(luaState, &it);
lua_pushstring(luaState, directory.c_str()); lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) { if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
+7 -7
View File
@@ -37,7 +37,7 @@
#include "lua/lua.hpp" #include "lua/lua.hpp"
#include "region_api.hpp" #include "region_api.hpp"
#include "pager_api.hpp" #include "region_pager_api.hpp"
#include "room_api.hpp" #include "room_api.hpp"
#include "room_mgr_api.hpp" #include "room_mgr_api.hpp"
#include "generator_api.hpp" #include "generator_api.hpp"
@@ -56,12 +56,12 @@ static const luaL_Reg loadedlibs[] = {
{LUA_MATHLIBNAME, luaopen_math}, {LUA_MATHLIBNAME, luaopen_math},
{LUA_DBLIBNAME, luaopen_debug}, {LUA_DBLIBNAME, luaopen_debug},
//custom libs //Tortuga's API
{LUA_REGIONLIBNAME, luaopen_regionapi}, {TORTUGA_REGION_NAME, openRegionAPI},
{LUA_PAGERLIBNAME, luaopen_pagerapi}, {TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI},
{LUA_ROOMLIBNAME, luaopen_roomapi}, {TORTUGA_ROOM_NAME, openRoomAPI},
{LUA_ROOMMGRLIBNAME, luaopen_roommgrapi}, {TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI},
{LUA_GENERATORLIBNAME, luaopen_generatorapi}, {TORTUGA_GENRATOR_NAME, openGeneratorAPI},
{NULL, NULL} {NULL, NULL}
}; };
+7 -7
View File
@@ -65,15 +65,15 @@ static int getMapHeight(lua_State* L) {
return 1; return 1;
} }
static const luaL_Reg generatorlib[] = { static const luaL_Reg generatorLib[] = {
{"gettype", getMapType}, {"GetMapType", getMapType},
{"getchunk", getChunk}, {"GetChunk", getChunk},
{"getmapwidth", getMapWidth}, {"GetMapWidth", getMapWidth},
{"getmapheight", getMapHeight}, {"GetMapHeight", getMapHeight},
{nullptr, nullptr} {nullptr, nullptr}
}; };
LUAMOD_API int luaopen_generatorapi(lua_State* L) { LUAMOD_API int openGeneratorAPI(lua_State* L) {
luaL_newlib(L, generatorlib); luaL_newlib(L, generatorLib);
return 1; return 1;
} }
+2 -3
View File
@@ -24,8 +24,7 @@
#include "lua/lua.hpp" #include "lua/lua.hpp"
#define LUA_GENERATORLIBNAME "generator" #define TORTUGA_GENRATOR_NAME "Generator"
LUAMOD_API int luaopen_generatorapi(lua_State* L); LUAMOD_API int openGeneratorAPI(lua_State* L);
#endif #endif
+17 -5
View File
@@ -35,15 +35,27 @@ static int getGenerator(lua_State* L) {
return 1; return 1;
} }
static int onCreate(lua_State* L) {
//TODO: onCreate()
return 0;
}
static int onUnload(lua_State* L) {
//TODO: onUnload()
return 0;
}
//TODO: parameters //TODO: parameters
static const luaL_Reg roomlib[] = { static const luaL_Reg roomLib[] = {
{"getpager",getPager}, {"GetPager",getPager},
{"getgenerator",getGenerator}, {"GetGenerator",getGenerator},
{"OnCreate", onCreate},
{"OnUnload", onUnload},
{nullptr, nullptr} {nullptr, nullptr}
}; };
LUAMOD_API int luaopen_roomapi(lua_State* L) { LUAMOD_API int openRoomAPI(lua_State* L) {
luaL_newlib(L, roomlib); luaL_newlib(L, roomLib);
return 1; return 1;
} }
+2 -2
View File
@@ -24,7 +24,7 @@
#include "lua/lua.hpp" #include "lua/lua.hpp"
#define LUA_ROOMLIBNAME "room" #define TORTUGA_ROOM_NAME "Room"
LUAMOD_API int luaopen_roomapi(lua_State* L); LUAMOD_API int openRoomAPI(lua_State* L);
#endif #endif
+6 -6
View File
@@ -73,14 +73,14 @@ static int unloadRoom(lua_State* L) {
return 0; return 0;
} }
static const luaL_Reg roommgrlib[] = { static const luaL_Reg roomMgrLib[] = {
{"getroom",getRoom}, {"GetRoom",getRoom},
{"createroom",createRoom}, {"CreateRoom",createRoom},
{"unloadroom",unloadRoom}, {"UnloadRoom",unloadRoom},
{nullptr, nullptr} {nullptr, nullptr}
}; };
LUAMOD_API int luaopen_roommgrapi(lua_State* L) { LUAMOD_API int openRoomMgrAPI(lua_State* L) {
luaL_newlib(L, roommgrlib); luaL_newlib(L, roomMgrLib);
return 1; return 1;
} }
+2 -2
View File
@@ -24,7 +24,7 @@
#include "lua/lua.hpp" #include "lua/lua.hpp"
#define LUA_ROOMMGRLIBNAME "roommgr" #define TORTUGA_ROOM_MGR_NAME "RoomMgr"
LUAMOD_API int luaopen_roommgrapi(lua_State* L); LUAMOD_API int openRoomMgrAPI(lua_State* L);
#endif #endif