diff options
author | kwolekr <kwolekr@minetest.net> | 2013-11-29 21:16:08 -0500 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2013-11-30 00:01:43 -0500 |
commit | 769b2d7c0582a6e294472aa9ac166d8d1064cd77 (patch) | |
tree | 945cc7b07be020247d9f8b68a538d8da8d8b08e9 /src/script | |
parent | 5be786c804d36e9950598a01cf39f05574af2acc (diff) | |
download | minetest-769b2d7c0582a6e294472aa9ac166d8d1064cd77.tar.gz minetest-769b2d7c0582a6e294472aa9ac166d8d1064cd77.tar.bz2 minetest-769b2d7c0582a6e294472aa9ac166d8d1064cd77.zip |
LuaVoxelManip: Add get_light_data() and set_light_data()
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/lua_api/l_vmanip.cpp | 44 | ||||
-rw-r--r-- | src/script/lua_api/l_vmanip.h | 3 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index db8884e10..5228b7c06 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -178,6 +178,48 @@ int LuaVoxelManip::l_set_lighting(lua_State *L) return 0; } +int LuaVoxelManip::l_get_light_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_Integer light = vm->m_data[i].param1; + lua_pushinteger(L, light); + lua_rawseti(L, -2, i + 1); + } + + return 1; +} + +int LuaVoxelManip::l_set_light_data(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + + LuaVoxelManip *o = checkobject(L, 1); + ManualMapVoxelManipulator *vm = o->vm; + + if (!lua_istable(L, 2)) + return 0; + + int volume = vm->m_area.getVolume(); + for (int i = 0; i != volume; i++) { + lua_rawgeti(L, 2, i + 1); + u8 light = lua_tointeger(L, -1); + + vm->m_data[i].param1 = light; + + lua_pop(L, 1); + } + + return 0; +} + int LuaVoxelManip::l_update_map(lua_State *L) { LuaVoxelManip *o = checkobject(L, 1); @@ -299,5 +341,7 @@ const luaL_reg LuaVoxelManip::methods[] = { luamethod(LuaVoxelManip, update_liquids), luamethod(LuaVoxelManip, calc_lighting), luamethod(LuaVoxelManip, set_lighting), + luamethod(LuaVoxelManip, get_light_data), + luamethod(LuaVoxelManip, set_light_data), {0,0} }; diff --git a/src/script/lua_api/l_vmanip.h b/src/script/lua_api/l_vmanip.h index d2f035a3e..b3393e09a 100644 --- a/src/script/lua_api/l_vmanip.h +++ b/src/script/lua_api/l_vmanip.h @@ -49,8 +49,11 @@ private: static int l_update_map(lua_State *L); static int l_update_liquids(lua_State *L); + static int l_calc_lighting(lua_State *L); static int l_set_lighting(lua_State *L); + static int l_get_light_data(lua_State *L); + static int l_set_light_data(lua_State *L); public: LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool is_mapgen_vm); |