Created the room system's API, and tweaked some other APIs
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
+2
-7
@@ -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}
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user