diff --git a/src/logic/scripting/lua/libs/libgeneration.cpp b/src/logic/scripting/lua/libs/libgeneration.cpp index 291b847f..2dd5746b 100644 --- a/src/logic/scripting/lua/libs/libgeneration.cpp +++ b/src/logic/scripting/lua/libs/libgeneration.cpp @@ -36,11 +36,19 @@ static int l_create_fragment(lua::State* L) { } static int l_load_fragment(lua::State* L) { - io::path path = lua::require_string(L, 1); - if (!io::exists(path)) { - throw std::runtime_error("file "+path.string()+" does not exist"); + dv::value map; + if (!lua::isstring(L, 1)) { + 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(bytearray.data()), bytearray.size() + ); } - auto map = io::read_binary_json(path); auto fragment = std::make_shared(); fragment->deserialize(map);