diff --git a/common/script/linit.cpp b/common/script/linit.cpp index 4f9eb81..c03a812 100644 --- a/common/script/linit.cpp +++ b/common/script/linit.cpp @@ -20,7 +20,7 @@ #define LUA_LIB #include "lua/lua.hpp" -#include "map_api.hpp" +#include "region_api.hpp" /* @@ -41,7 +41,7 @@ static const luaL_Reg loadedlibs[] = { {LUA_DBLIBNAME, luaopen_debug}, /* custom libs */ - {LUA_MAPLIBNAME, luaopen_mapapi}, + {LUA_REGIONLIBNAME, luaopen_regionapi}, {NULL, NULL} }; diff --git a/common/script/map_api.cpp b/common/script/region_api.cpp similarity index 52% rename from common/script/map_api.cpp rename to common/script/region_api.cpp index 20aa681..c94691b 100644 --- a/common/script/map_api.cpp +++ b/common/script/region_api.cpp @@ -19,58 +19,22 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#include "map_api.hpp" +#include "region_api.hpp" -//map headers -#include "region_pager.hpp" - -//NOTE: When operating on a region, setTile() & getTile() *are not* zero indexed, but when operating on the entire map they *are* zero indexed. -//TODO: enforce all possible parameter counts -//TODO: update the map API to handle multiple rooms +#include "region.hpp" static int setTile(lua_State* L) { - if (lua_gettop(L) == 5) { - //operating on a region - Region* ptr = (Region*)lua_touserdata(L, 1); - ptr->SetTile(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_tointeger(L, 4)-1, lua_tointeger(L, 5)); - } - else { - //operating on the whole map - lua_pushstring(L, "pager"); - lua_gettable(L, LUA_REGISTRYINDEX); - - //assume the pager is using lua - RegionPager* pager = reinterpret_cast(lua_touserdata(L, -1)); - - //balance the stack - lua_pop(L, 1); - - pager->SetTile(lua_tointeger(L, 1), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4)); - } + //operating on a region + Region* ptr = (Region*)lua_touserdata(L, 1); + ptr->SetTile(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_tointeger(L, 4)-1, lua_tointeger(L, 5)); return 0; } static int getTile(lua_State* L) { - if (lua_gettop(L) == 4) { - //operating on a region - Region* ptr = (Region*)lua_touserdata(L, 1); - int ret = ptr->GetTile(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_tointeger(L, 4)-1); - lua_pushnumber(L, ret); - } - else { - //operating on the whole map - lua_pushstring(L, "pager"); - lua_gettable(L, LUA_REGISTRYINDEX); - - //assume the pager is using lua - RegionPager* pager = reinterpret_cast(lua_touserdata(L, -1)); - - //balance the stack - lua_pop(L, 1); - - int ret = pager->GetTile(lua_tointeger(L, 1), lua_tointeger(L, 2), lua_tointeger(L, 3)); - lua_pushnumber(L, ret); - } + //operating on a region + Region* ptr = (Region*)lua_touserdata(L, 1); + int ret = ptr->GetTile(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_tointeger(L, 4)-1); + lua_pushnumber(L, ret); return 1; } @@ -101,15 +65,7 @@ static int getRegionDepth(lua_State* L) { return 1; } -static int dummy(lua_State* L) { - return 0; -} - static const luaL_Reg regionlib[] = { - {"create", dummy}, - {"unload", dummy}, - {"load", dummy}, - {"save", dummy}, {"settile",setTile}, {"gettile",getTile}, {"getx",getX}, @@ -120,7 +76,7 @@ static const luaL_Reg regionlib[] = { {nullptr, nullptr} }; -LUAMOD_API int luaopen_mapapi(lua_State* L) { +LUAMOD_API int luaopen_regionapi(lua_State* L) { luaL_newlib(L, regionlib); return 1; } \ No newline at end of file diff --git a/common/script/map_api.hpp b/common/script/region_api.hpp similarity index 87% rename from common/script/map_api.hpp rename to common/script/region_api.hpp index efa2abd..310074d 100644 --- a/common/script/map_api.hpp +++ b/common/script/region_api.hpp @@ -19,12 +19,12 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef MAPAPI_HPP_ -#define MAPAPI_HPP_ +#ifndef REGIONAPI_HPP_ +#define REGIONAPI_HPP_ #include "lua/lua.hpp" -#define LUA_MAPLIBNAME "map" -LUAMOD_API int luaopen_mapapi(lua_State* L); +#define LUA_REGIONLIBNAME "region" +LUAMOD_API int luaopen_regionapi(lua_State* L); #endif