Skip to content

Commit

Permalink
LuaVoxelManip: Add get_param2_data and set_param2_data
Browse files Browse the repository at this point in the history
  • Loading branch information
kwolekr committed Jan 19, 2014
1 parent 21c9624 commit bafc4ac
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/script/lua_api/l_vmanip.cpp
Expand Up @@ -229,6 +229,48 @@ int LuaVoxelManip::l_set_light_data(lua_State *L)
return 0;
}

int LuaVoxelManip::l_get_param2_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 param2 = vm->m_data[i].param2;
lua_pushinteger(L, param2);
lua_rawseti(L, -2, i + 1);
}

return 1;
}

int LuaVoxelManip::l_set_param2_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 param2 = lua_tointeger(L, -1);

vm->m_data[i].param2 = param2;

lua_pop(L, 1);
}

return 0;
}

int LuaVoxelManip::l_update_map(lua_State *L)
{
LuaVoxelManip *o = checkobject(L, 1);
Expand Down Expand Up @@ -352,5 +394,7 @@ const luaL_reg LuaVoxelManip::methods[] = {
luamethod(LuaVoxelManip, set_lighting),
luamethod(LuaVoxelManip, get_light_data),
luamethod(LuaVoxelManip, set_light_data),
luamethod(LuaVoxelManip, get_param2_data),
luamethod(LuaVoxelManip, set_param2_data),
{0,0}
};
3 changes: 3 additions & 0 deletions src/script/lua_api/l_vmanip.h
Expand Up @@ -55,6 +55,9 @@ class LuaVoxelManip : public ModApiBase {
static int l_get_light_data(lua_State *L);
static int l_set_light_data(lua_State *L);

static int l_get_param2_data(lua_State *L);
static int l_set_param2_data(lua_State *L);

public:
LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool is_mapgen_vm);
LuaVoxelManip(Map *map);
Expand Down

0 comments on commit bafc4ac

Please sign in to comment.