From 0debe32da4769c59f274b093b39a1a0cdac298a2 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 16 Jun 2024 23:23:13 +0300 Subject: [PATCH] revert file.read_bytes --- src/logic/scripting/lua/libfile.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/logic/scripting/lua/libfile.cpp b/src/logic/scripting/lua/libfile.cpp index 3a00e0dd..5c5dc27b 100644 --- a/src/logic/scripting/lua/libfile.cpp +++ b/src/logic/scripting/lua/libfile.cpp @@ -109,8 +109,18 @@ static int l_file_mkdirs(lua::State* L) { static int l_file_read_bytes(lua::State* L) { fs::path path = resolve_path(lua::require_string(L, 1)); if (fs::is_regular_file(path)) { - auto bytes = files::read_bytes(path); - return lua::newuserdata(L, std::move(bytes)); + size_t length = static_cast(fs::file_size(path)); + + auto bytes = files::read_bytes(path, length); + + lua::createtable(L, length, 0); + int newTable = lua::gettop(L); + + for(size_t i = 0; i < length; i++) { + lua::pushinteger(L, bytes[i]); + lua::rawseti(L, i+1, newTable); + } + return 1; } throw std::runtime_error("file does not exists "+util::quote(path.u8string())); }