summaryrefslogtreecommitdiff
path: root/library/LuaApi.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-05-13 13:58:41 +0400
committerAlexander Gavrilov2012-05-13 13:58:41 +0400
commit87ec1de891625e9dc68924c570ede0fe23b4b6b7 (patch)
treebedeb0dbfa1ba179c6ad803ed0c253515d73bdc6 /library/LuaApi.cpp
parentc6b52067bd90a2f7832a94a74cfd0e4ec0a8641c (diff)
downloaddfhack-87ec1de891625e9dc68924c570ede0fe23b4b6b7.tar.gz
dfhack-87ec1de891625e9dc68924c570ede0fe23b4b6b7.tar.bz2
dfhack-87ec1de891625e9dc68924c570ede0fe23b4b6b7.tar.xz
Improve lua api for tile biome access.
Diffstat (limited to 'library/LuaApi.cpp')
-rw-r--r--library/LuaApi.cpp52
1 files changed, 51 insertions, 1 deletions
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp
index 1baa4045..529bdd07 100644
--- a/library/LuaApi.cpp
+++ b/library/LuaApi.cpp
@@ -94,6 +94,26 @@ void Lua::Push(lua_State *state, const Units::NoblePosition &pos)
lua_setfield(state, -2, "position");
}
+void Lua::Push(lua_State *state, df::coord pos)
+{
+ lua_createtable(state, 0, 3);
+ lua_pushinteger(state, pos.x);
+ lua_setfield(state, -2, "x");
+ lua_pushinteger(state, pos.y);
+ lua_setfield(state, -2, "y");
+ lua_pushinteger(state, pos.z);
+ lua_setfield(state, -2, "z");
+}
+
+void Lua::Push(lua_State *state, df::coord2d pos)
+{
+ lua_createtable(state, 0, 2);
+ lua_pushinteger(state, pos.x);
+ lua_setfield(state, -2, "x");
+ lua_pushinteger(state, pos.y);
+ lua_setfield(state, -2, "y");
+}
+
int Lua::PushPosXYZ(lua_State *state, df::coord pos)
{
if (!pos.isValid())
@@ -110,6 +130,21 @@ int Lua::PushPosXYZ(lua_State *state, df::coord pos)
}
}
+int Lua::PushPosXY(lua_State *state, df::coord2d pos)
+{
+ if (!pos.isValid())
+ {
+ lua_pushnil(state);
+ return 1;
+ }
+ else
+ {
+ lua_pushinteger(state, pos.x);
+ lua_pushinteger(state, pos.y);
+ return 2;
+ }
+}
+
static df::coord2d CheckCoordXY(lua_State *state, int base, bool vararg = false)
{
df::coord2d p;
@@ -754,7 +789,6 @@ static const luaL_Reg dfhack_items_funcs[] = {
static const LuaWrapper::FunctionReg dfhack_maps_module[] = {
WRAPN(getBlock, (df::map_block* (*)(int32_t,int32_t,int32_t))Maps::getBlock),
- WRAPM(Maps, getRegionBiome),
WRAPM(Maps, enableBlockUpdates),
WRAPM(Maps, getGlobalInitFeature),
WRAPM(Maps, getLocalInitFeature),
@@ -769,8 +803,24 @@ static int maps_getTileBlock(lua_State *L)
return 1;
}
+static int maps_getRegionBiome(lua_State *L)
+{
+ auto pos = CheckCoordXY(L, 1, true);
+ Lua::PushDFObject(L, Maps::getRegionBiome(pos));
+ return 1;
+}
+
+static int maps_getTileBiomeRgn(lua_State *L)
+{
+ auto pos = CheckCoordXYZ(L, 1, true);
+ Lua::PushPosXY(L, Maps::getTileBiomeRgn(pos));
+ return 1;
+}
+
static const luaL_Reg dfhack_maps_funcs[] = {
{ "getTileBlock", maps_getTileBlock },
+ { "getRegionBiome", maps_getRegionBiome },
+ { "getTileBiomeRgn", maps_getTileBiomeRgn },
{ NULL, NULL }
};