update block.compose_state, block.decompose_state semantics
This commit is contained in:
parent
3a1ae57bbf
commit
eefaafd1e7
@ -34,10 +34,10 @@ block.place(x: int, y: int, z: int, id: int, states: int, [optional] playerid: i
|
||||
block.destruct(x: int, y: int, z: int, playerid: int)
|
||||
|
||||
-- Compose the complete state as an integer
|
||||
block.compose_state(rotation: int, segment: int, userbits: int) -> int
|
||||
block.compose_state(state: {rotation: int, segment: int, userbits: int}) -> int
|
||||
|
||||
-- Decompose the complete state into: rotation, segment, user bits
|
||||
block.decompose_state(state: int) -> int, int, int
|
||||
block.decompose_state(state: int) -> {int, int, int}
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
|
||||
@ -33,10 +33,10 @@ block.place(x: int, y: int, z: int, id: int, states: int, [optional] playerid: i
|
||||
block.destruct(x: int, y: int, z: int, playerid: int)
|
||||
|
||||
-- Собирает полное состояние в виде целого числа
|
||||
block.compose_state(rotation: int, segment: int, userbits: int) -> int
|
||||
block.compose_state(state: {rotation: int, segment: int, userbits: int}) -> int
|
||||
|
||||
-- Разбирает полное состояние на: вращение, сегмент, пользовательские биты
|
||||
block.decompose_state(state: int) -> int, int, int
|
||||
block.decompose_state(state: int) -> {int, int, int}
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
|
||||
@ -381,20 +381,32 @@ static int l_raycast(lua::State* L) {
|
||||
}
|
||||
|
||||
static int l_compose_state(lua::State* L) {
|
||||
if (lua::istable(L, 1) || lua::objlen(L, 1) < 3) {
|
||||
throw std::runtime_error("expected array of 3 integers");
|
||||
}
|
||||
blockstate state {};
|
||||
state.rotation = lua::tointeger(L, 1);
|
||||
state.segment = lua::tointeger(L, 2);
|
||||
state.userbits = lua::tointeger(L, 3);
|
||||
|
||||
lua::rawgeti(L, 1, 1); state.rotation = lua::tointeger(L, -1); lua::pop(L);
|
||||
lua::rawgeti(L, 2, 1); state.segment = lua::tointeger(L, -1); lua::pop(L);
|
||||
lua::rawgeti(L, 3, 1); state.userbits = lua::tointeger(L, -1); lua::pop(L);
|
||||
|
||||
return lua::pushinteger(L, blockstate2int(state));
|
||||
}
|
||||
|
||||
static int l_decompose_state(lua::State* L) {
|
||||
auto stateInt = static_cast<blockstate_t>(lua::tointeger(L, 1));
|
||||
auto state = int2blockstate(stateInt);
|
||||
|
||||
lua::createtable(L, 3, 0);
|
||||
lua::pushinteger(L, state.rotation);
|
||||
lua::rawseti(L, 1);
|
||||
|
||||
lua::pushinteger(L, state.segment);
|
||||
lua::rawseti(L, 2);
|
||||
|
||||
lua::pushinteger(L, state.userbits);
|
||||
return 3;
|
||||
lua::rawseti(L, 3);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg blocklib [] = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user