diff --git a/src/logic/scripting/lua/libs/libworld.cpp b/src/logic/scripting/lua/libs/libworld.cpp index 5d9368420..bbba422df 100644 --- a/src/logic/scripting/lua/libs/libworld.cpp +++ b/src/logic/scripting/lua/libs/libworld.cpp @@ -160,13 +160,13 @@ static void integrate_chunk_client(Chunk& chunk) { static int l_set_chunk_data(lua::State* L) { int x = static_cast(lua::tointeger(L, 1)); int z = static_cast(lua::tointeger(L, 2)); - auto buffer = lua::touserdata(L, 3); + auto buffer = lua::require_bytearray(L, 3); auto chunk = level->chunks->getChunk(x, z); if (chunk == nullptr) { - return 0; + return lua::pushboolean(L, false); } compressed_chunks::decode( - *chunk, buffer->data().data(), buffer->data().size() + *chunk, buffer.data(), buffer.size() ); if (controller->getChunksController()->lighting == nullptr) { return lua::pushboolean(L, true); diff --git a/src/logic/scripting/lua/lua_util.cpp b/src/logic/scripting/lua/lua_util.cpp index d008cf458..23d13d7f7 100644 --- a/src/logic/scripting/lua/lua_util.cpp +++ b/src/logic/scripting/lua/lua_util.cpp @@ -133,6 +133,13 @@ dv::value lua::tovalue(State* L, int idx) { return map; } } + case LUA_TUSERDATA: { + if (auto bytes = touserdata(L, idx)) { + const auto& data = bytes->data(); + return std::make_shared(data.data(), data.size()); + } + [[fallthrough]]; + } default: throw std::runtime_error( "lua type " + std::string(lua_typename(L, type)) +