add bytearray option for generation.load_fragment (#597)
This commit is contained in:
parent
17f3e03ea9
commit
8c7409eed1
@ -36,11 +36,19 @@ static int l_create_fragment(lua::State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int l_load_fragment(lua::State* L) {
|
static int l_load_fragment(lua::State* L) {
|
||||||
io::path path = lua::require_string(L, 1);
|
dv::value map;
|
||||||
if (!io::exists(path)) {
|
if (!lua::isstring(L, 1)) {
|
||||||
throw std::runtime_error("file "+path.string()+" does not exist");
|
io::path path = lua::require_string(L, 1);
|
||||||
|
if (!io::exists(path)) {
|
||||||
|
throw std::runtime_error("file "+path.string()+" does not exist");
|
||||||
|
}
|
||||||
|
map = io::read_binary_json(path);
|
||||||
|
} else {
|
||||||
|
auto bytearray = lua::bytearray_as_string(L, 1);
|
||||||
|
map = json::from_binary(
|
||||||
|
reinterpret_cast<const ubyte*>(bytearray.data()), bytearray.size()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
auto map = io::read_binary_json(path);
|
|
||||||
|
|
||||||
auto fragment = std::make_shared<VoxelFragment>();
|
auto fragment = std::make_shared<VoxelFragment>();
|
||||||
fragment->deserialize(map);
|
fragment->deserialize(map);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user