aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_env.cpp11
-rw-r--r--src/script/lua_api/l_vmanip.cpp54
-rw-r--r--src/script/lua_api/l_vmanip.h7
3 files changed, 43 insertions, 29 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index b6bafbcd9..02cafc0d5 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -594,22 +594,13 @@ int ModApiEnvMod::l_get_mapgen_object(lua_State *L)
luaL_getmetatable(L, "VoxelManip");
lua_setmetatable(L, -2);
- // VoxelManip data
- int volume = vm->m_area.getVolume();
- lua_newtable(L);
- for (int i = 0; i != volume; i++) {
- lua_Number cid = vm->m_data[i].getContent();
- lua_pushnumber(L, cid);
- lua_rawseti(L, -2, i + 1);
- }
-
// emerged min pos
push_v3s16(L, vm->m_area.MinEdge);
// emerged max pos
push_v3s16(L, vm->m_area.MaxEdge);
- nargs = 4;
+ nargs = 3;
break; }
case MGOBJ_HEIGHTMAP: {
diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp
index 6743f40f9..f753f5f27 100644
--- a/src/script/lua_api/l_vmanip.cpp
+++ b/src/script/lua_api/l_vmanip.cpp
@@ -39,42 +39,52 @@ int LuaVoxelManip::gc_object(lua_State *L)
return 0;
}
-int LuaVoxelManip::l_read_chunk(lua_State *L)
+int LuaVoxelManip::l_read_from_map(lua_State *L)
{
LuaVoxelManip *o = checkobject(L, 1);
+ ManualMapVoxelManipulator *vm = o->vm;
v3s16 bp1 = getNodeBlockPos(read_v3s16(L, 2));
v3s16 bp2 = getNodeBlockPos(read_v3s16(L, 3));
sortBoxVerticies(bp1, bp2);
- ManualMapVoxelManipulator *vm = o->vm;
+
vm->initialEmerge(bp1, bp2);
- v3s16 emerged_p1 = vm->m_area.MinEdge;
- v3s16 emerged_p2 = vm->m_area.MaxEdge;
+ push_v3s16(L, vm->m_area.MinEdge);
+ push_v3s16(L, vm->m_area.MaxEdge);
+
+ return 2;
+}
+
+int LuaVoxelManip::l_get_data(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+
+ LuaVoxelManip *o = checkobject(L, 1);
+ ManualMapVoxelManipulator *vm = o->vm;
int volume = vm->m_area.getVolume();
lua_newtable(L);
for (int i = 0; i != volume; i++) {
- lua_Number cid = vm->m_data[i].getContent();
- lua_pushnumber(L, cid);
+ lua_Integer cid = vm->m_data[i].getContent();
+ lua_pushinteger(L, cid);
lua_rawseti(L, -2, i + 1);
}
- push_v3s16(L, emerged_p1);
- push_v3s16(L, emerged_p2);
-
- return 3;
+ return 1;
}
-int LuaVoxelManip::l_write_chunk(lua_State *L)
+int LuaVoxelManip::l_set_data(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
+
LuaVoxelManip *o = checkobject(L, 1);
+ ManualMapVoxelManipulator *vm = o->vm;
+
if (!lua_istable(L, 2))
return 0;
- ManualMapVoxelManipulator *vm = o->vm;
-
int volume = vm->m_area.getVolume();
for (int i = 0; i != volume; i++) {
lua_rawgeti(L, 2, i + 1);
@@ -84,10 +94,18 @@ int LuaVoxelManip::l_write_chunk(lua_State *L)
lua_pop(L, 1);
}
+
+ return 0;
+}
+
+int LuaVoxelManip::l_write_to_map(lua_State *L)
+{
+ LuaVoxelManip *o = checkobject(L, 1);
+ ManualMapVoxelManipulator *vm = o->vm;
vm->blitBackAll(&o->modified_blocks);
-
- return 0;
+
+ return 0;
}
int LuaVoxelManip::l_update_liquids(lua_State *L)
@@ -258,8 +276,10 @@ void LuaVoxelManip::Register(lua_State *L)
const char LuaVoxelManip::className[] = "VoxelManip";
const luaL_reg LuaVoxelManip::methods[] = {
- luamethod(LuaVoxelManip, read_chunk),
- luamethod(LuaVoxelManip, write_chunk),
+ luamethod(LuaVoxelManip, read_from_map),
+ luamethod(LuaVoxelManip, get_data),
+ luamethod(LuaVoxelManip, set_data),
+ luamethod(LuaVoxelManip, write_to_map),
luamethod(LuaVoxelManip, update_map),
luamethod(LuaVoxelManip, update_liquids),
luamethod(LuaVoxelManip, calc_lighting),
diff --git a/src/script/lua_api/l_vmanip.h b/src/script/lua_api/l_vmanip.h
index 5a57d6bfa..7720ec040 100644
--- a/src/script/lua_api/l_vmanip.h
+++ b/src/script/lua_api/l_vmanip.h
@@ -43,8 +43,11 @@ private:
static int gc_object(lua_State *L);
- static int l_read_chunk(lua_State *L);
- static int l_write_chunk(lua_State *L);
+ static int l_read_from_map(lua_State *L);
+ static int l_get_data(lua_State *L);
+ static int l_set_data(lua_State *L);
+ static int l_write_to_map(lua_State *L);
+
static int l_update_map(lua_State *L);
static int l_update_liquids(lua_State *L);
static int l_calc_lighting(lua_State *L);