diff --git a/common/map/region_api.cpp b/common/map/region_api.cpp index b30f04f..98f5ee1 100644 --- a/common/map/region_api.cpp +++ b/common/map/region_api.cpp @@ -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; } \ No newline at end of file diff --git a/common/map/region_api.hpp b/common/map/region_api.hpp index 310074d..6e6733f 100644 --- a/common/map/region_api.hpp +++ b/common/map/region_api.hpp @@ -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 diff --git a/common/map/pager_api.cpp b/common/map/region_pager_api.cpp similarity index 59% rename from common/map/pager_api.cpp rename to common/map/region_pager_api.cpp index 8f60e61..f38d1e2 100644 --- a/common/map/pager_api.cpp +++ b/common/map/region_pager_api.cpp @@ -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 #include +//DOCS: These functions are just wrappers for the RegionPagerLua class + static int setTile(lua_State* L) { RegionPagerLua* pager = reinterpret_cast(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(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(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(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(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; } \ No newline at end of file diff --git a/common/map/pager_api.hpp b/common/map/region_pager_api.hpp similarity index 91% rename from common/map/pager_api.hpp rename to common/map/region_pager_api.hpp index 2531e94..bc40981 100644 --- a/common/map/pager_api.hpp +++ b/common/map/region_pager_api.hpp @@ -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 diff --git a/common/map/region_pager_lua.cpp b/common/map/region_pager_lua.cpp index a183be8..a402f27 100644 --- a/common/map/region_pager_lua.cpp +++ b/common/map/region_pager_lua.cpp @@ -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, ®ionList.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, ®ionList.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, ®ion); 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) { diff --git a/server/linit.cpp b/server/linit.cpp index 7898184..8108a49 100644 --- a/server/linit.cpp +++ b/server/linit.cpp @@ -37,7 +37,7 @@ #include "lua/lua.hpp" #include "region_api.hpp" -#include "pager_api.hpp" +#include "region_pager_api.hpp" #include "room_api.hpp" #include "room_mgr_api.hpp" #include "generator_api.hpp" @@ -56,12 +56,12 @@ static const luaL_Reg loadedlibs[] = { {LUA_MATHLIBNAME, luaopen_math}, {LUA_DBLIBNAME, luaopen_debug}, - //custom libs - {LUA_REGIONLIBNAME, luaopen_regionapi}, - {LUA_PAGERLIBNAME, luaopen_pagerapi}, - {LUA_ROOMLIBNAME, luaopen_roomapi}, - {LUA_ROOMMGRLIBNAME, luaopen_roommgrapi}, - {LUA_GENERATORLIBNAME, luaopen_generatorapi}, + //Tortuga's API + {TORTUGA_REGION_NAME, openRegionAPI}, + {TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI}, + {TORTUGA_ROOM_NAME, openRoomAPI}, + {TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI}, + {TORTUGA_GENRATOR_NAME, openGeneratorAPI}, {NULL, NULL} }; diff --git a/server/mapgen/generator_api.cpp b/server/mapgen/generator_api.cpp index c3b0eb9..f3cc84f 100644 --- a/server/mapgen/generator_api.cpp +++ b/server/mapgen/generator_api.cpp @@ -65,15 +65,15 @@ static int getMapHeight(lua_State* L) { return 1; } -static const luaL_Reg generatorlib[] = { - {"gettype", getMapType}, - {"getchunk", getChunk}, - {"getmapwidth", getMapWidth}, - {"getmapheight", getMapHeight}, +static const luaL_Reg generatorLib[] = { + {"GetMapType", getMapType}, + {"GetChunk", getChunk}, + {"GetMapWidth", getMapWidth}, + {"GetMapHeight", getMapHeight}, {nullptr, nullptr} }; -LUAMOD_API int luaopen_generatorapi(lua_State* L) { - luaL_newlib(L, generatorlib); +LUAMOD_API int openGeneratorAPI(lua_State* L) { + luaL_newlib(L, generatorLib); return 1; } diff --git a/server/mapgen/generator_api.hpp b/server/mapgen/generator_api.hpp index a0b9fb3..78c24c2 100644 --- a/server/mapgen/generator_api.hpp +++ b/server/mapgen/generator_api.hpp @@ -24,8 +24,7 @@ #include "lua/lua.hpp" -#define LUA_GENERATORLIBNAME "generator" -LUAMOD_API int luaopen_generatorapi(lua_State* L); - +#define TORTUGA_GENRATOR_NAME "Generator" +LUAMOD_API int openGeneratorAPI(lua_State* L); #endif \ No newline at end of file diff --git a/server/rooms/room_api.cpp b/server/rooms/room_api.cpp index 51c0101..3f217a8 100644 --- a/server/rooms/room_api.cpp +++ b/server/rooms/room_api.cpp @@ -35,15 +35,27 @@ static int getGenerator(lua_State* L) { return 1; } +static int onCreate(lua_State* L) { + //TODO: onCreate() + return 0; +} + +static int onUnload(lua_State* L) { + //TODO: onUnload() + return 0; +} + //TODO: parameters -static const luaL_Reg roomlib[] = { - {"getpager",getPager}, - {"getgenerator",getGenerator}, +static const luaL_Reg roomLib[] = { + {"GetPager",getPager}, + {"GetGenerator",getGenerator}, + {"OnCreate", onCreate}, + {"OnUnload", onUnload}, {nullptr, nullptr} }; -LUAMOD_API int luaopen_roomapi(lua_State* L) { - luaL_newlib(L, roomlib); +LUAMOD_API int openRoomAPI(lua_State* L) { + luaL_newlib(L, roomLib); return 1; } \ No newline at end of file diff --git a/server/rooms/room_api.hpp b/server/rooms/room_api.hpp index a9c31a8..5d2eab8 100644 --- a/server/rooms/room_api.hpp +++ b/server/rooms/room_api.hpp @@ -24,7 +24,7 @@ #include "lua/lua.hpp" -#define LUA_ROOMLIBNAME "room" -LUAMOD_API int luaopen_roomapi(lua_State* L); +#define TORTUGA_ROOM_NAME "Room" +LUAMOD_API int openRoomAPI(lua_State* L); #endif diff --git a/server/rooms/room_mgr_api.cpp b/server/rooms/room_mgr_api.cpp index 0e58729..aae40df 100644 --- a/server/rooms/room_mgr_api.cpp +++ b/server/rooms/room_mgr_api.cpp @@ -73,14 +73,14 @@ static int unloadRoom(lua_State* L) { return 0; } -static const luaL_Reg roommgrlib[] = { - {"getroom",getRoom}, - {"createroom",createRoom}, - {"unloadroom",unloadRoom}, +static const luaL_Reg roomMgrLib[] = { + {"GetRoom",getRoom}, + {"CreateRoom",createRoom}, + {"UnloadRoom",unloadRoom}, {nullptr, nullptr} }; -LUAMOD_API int luaopen_roommgrapi(lua_State* L) { - luaL_newlib(L, roommgrlib); +LUAMOD_API int openRoomMgrAPI(lua_State* L) { + luaL_newlib(L, roomMgrLib); return 1; } \ No newline at end of file diff --git a/server/rooms/room_mgr_api.hpp b/server/rooms/room_mgr_api.hpp index 1382b4d..f870e5e 100644 --- a/server/rooms/room_mgr_api.hpp +++ b/server/rooms/room_mgr_api.hpp @@ -24,7 +24,7 @@ #include "lua/lua.hpp" -#define LUA_ROOMMGRLIBNAME "roommgr" -LUAMOD_API int luaopen_roommgrapi(lua_State* L); +#define TORTUGA_ROOM_MGR_NAME "RoomMgr" +LUAMOD_API int openRoomMgrAPI(lua_State* L); #endif