diff --git a/common/map/map_system_api.cpp b/common/map/map_system_api.cpp index c3a9cca..46b6355 100644 --- a/common/map/map_system_api.cpp +++ b/common/map/map_system_api.cpp @@ -24,7 +24,10 @@ //all map API headers #include "region_api.hpp" #include "region_pager_api.hpp" -#include "tile_sheet.hpp" +#include "tile_sheet_api.hpp" + +//macros +#include "region.hpp" //useful "globals" static int getRegionWidth(lua_State* L) { @@ -43,7 +46,7 @@ static int getRegionDepth(lua_State* L) { } //This mimics linit.c to create a nested collection of all map modules. -static const luaL_Reg mapfuncs[] = { +static const luaL_Reg funcs[] = { //synonyms {"GetRegionWidth", getRegionWidth}, {"GetRegionHeight", getRegionHeight}, @@ -51,7 +54,7 @@ static const luaL_Reg mapfuncs[] = { {nullptr, nullptr} }; -static const luaL_Reg maplibs[] = { +static const luaL_Reg libs[] = { {"Region", openRegionAPI}, {"RegionPager", openRegionPagerAPI}, // {"TileSheet", openTileSheetAPI}, @@ -60,13 +63,13 @@ static const luaL_Reg maplibs[] = { int openMapSystemAPI(lua_State* L) { //create the table - luaL_newlibtable(L, maplibs); + luaL_newlibtable(L, libs); //push the "global" functions - luaL_setfuncs(L, mapfuncs, 0); + luaL_setfuncs(L, funcs, 0); //push the substable - for (const luaL_Reg* lib = maplibs; lib->func; lib++) { + for (const luaL_Reg* lib = libs; lib->func; lib++) { lua_pushcfunction(L, lib->func); lua_setfield(L, -2, lib->name); } diff --git a/server/linit.cpp b/server/linit.cpp index 7702d51..c442680 100644 --- a/server/linit.cpp +++ b/server/linit.cpp @@ -41,8 +41,7 @@ #endif #include "map_system_api.hpp" -#include "room_api.hpp" -#include "room_manager_api.hpp" +#include "room_system_api.hpp" //these libs are loaded by lua.c and are readily available to any Lua program static const luaL_Reg loadedlibs[] = { @@ -57,11 +56,6 @@ static const luaL_Reg loadedlibs[] = { {LUA_BITLIBNAME, luaopen_bit32}, {LUA_MATHLIBNAME, luaopen_math}, {LUA_DBLIBNAME, luaopen_debug}, - - //Tortuga's API - {TORTUGA_ROOM_NAME, openRoomAPI}, - {TORTUGA_ROOM_MANAGER_NAME, openRoomManagerAPI}, - {NULL, NULL} }; @@ -69,6 +63,7 @@ static const luaL_Reg loadedlibs[] = { //these libs are preloaded and must be required before used static const luaL_Reg preloadedlibs[] = { {TORTUGA_MAP_SYSTEM_API, openMapSystemAPI}, + {TORTUGA_ROOM_SYSTEM_API, openRoomSystemAPI}, {NULL, NULL} }; diff --git a/server/rooms/room_api.hpp b/server/rooms/room_api.hpp index 060a68d..087c6c2 100644 --- a/server/rooms/room_api.hpp +++ b/server/rooms/room_api.hpp @@ -28,7 +28,7 @@ #include "lua.hpp" #endif -#define TORTUGA_ROOM_NAME "room" +#define TORTUGA_ROOM_API "room" LUAMOD_API int openRoomAPI(lua_State* L); #endif diff --git a/server/rooms/room_manager_api.hpp b/server/rooms/room_manager_api.hpp index 8ca0418..1cd042d 100644 --- a/server/rooms/room_manager_api.hpp +++ b/server/rooms/room_manager_api.hpp @@ -28,7 +28,7 @@ #include "lua.hpp" #endif -#define TORTUGA_ROOM_MANAGER_NAME "room_manager" +#define TORTUGA_ROOM_MANAGER_API "room_manager" LUAMOD_API int openRoomManagerAPI(lua_State* L); -#endif +#endif \ No newline at end of file diff --git a/server/rooms/room_system_api.cpp b/server/rooms/room_system_api.cpp new file mode 100644 index 0000000..fcbb205 --- /dev/null +++ b/server/rooms/room_system_api.cpp @@ -0,0 +1,56 @@ +/* Copyright: (c) Kayne Ruse 2014 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#include "room_system_api.hpp" + +//all map API headers +#include "room_api.hpp" +#include "room_manager_api.hpp" + +//useful "globals" +//... + +//This mimics linit.c to create a nested collection of all map modules. +static const luaL_Reg funcs[] = { + {nullptr, nullptr} +}; + +static const luaL_Reg libs[] = { + {"Room", openRoomAPI}, + {"RoomManager", openRoomManagerAPI}, +// {"TileSheet", openTileSheetAPI}, + {nullptr, nullptr} +}; + +int openMapSystemAPI(lua_State* L) { + //create the table + luaL_newlibtable(L, libs); + + //push the "global" functions + luaL_setfuncs(L, funcs, 0); + + //push the substable + for (const luaL_Reg* lib = libs; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_setfield(L, -2, lib->name); + } + return 1; +} \ No newline at end of file diff --git a/server/rooms/room_system_api.hpp b/server/rooms/room_system_api.hpp new file mode 100644 index 0000000..9006ce5 --- /dev/null +++ b/server/rooms/room_system_api.hpp @@ -0,0 +1,34 @@ +/* Copyright: (c) Kayne Ruse 2014 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#ifndef ROOMSYSTEMAPI_HPP_ +#define ROOMSYSTEMAPI_HPP_ + +#if defined(__MINGW32__) + #include "lua/lua.hpp" +#else + #include "lua.hpp" +#endif + +#define TORTUGA_ROOM_SYSTEM_API "room_system" +LUAMOD_API int openRoomSystemAPI(lua_State* L); + +#endif \ No newline at end of file