From a015d74af5fd7de6bc187c7d96e136090f0608a6 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 19 Nov 2024 10:04:26 +0300 Subject: [PATCH] update file library warnings --- res/scripts/stdmin.lua | 7 +++++++ src/logic/scripting/lua/libs/libfile.cpp | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/res/scripts/stdmin.lua b/res/scripts/stdmin.lua index 996af40e..924c235f 100644 --- a/res/scripts/stdmin.lua +++ b/res/scripts/stdmin.lua @@ -314,3 +314,10 @@ function __vc__error(msg, frame) end return debug.traceback(msg, frame) end + +function __vc_warning(msg, detail, n) + if events then + events.emit( + "core:warning", msg, detail, debug.get_traceback(1 + (n or 0))) + end +end diff --git a/src/logic/scripting/lua/libs/libfile.cpp b/src/logic/scripting/lua/libs/libfile.cpp index 2c0c2f9e..d436bdfd 100644 --- a/src/logic/scripting/lua/libs/libfile.cpp +++ b/src/logic/scripting/lua/libs/libfile.cpp @@ -57,11 +57,12 @@ static fs::path get_writeable_path(lua::State* L) { fs::path path = resolve_path(rawpath); auto entryPoint = rawpath.substr(0, rawpath.find(':')); if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) { - lua::emit_event(L, "core:warning", [=](auto L) { + if (lua::getglobal(L, "__vc_warning")) { lua::pushstring(L, "writing to read-only entry point"); lua::pushstring(L, entryPoint); - return 2; - }); + lua::pushinteger(L, 1); + lua::call_nothrow(L, 3); + } } return path; }