From 35448bf0fe863662c22032f9623cada7841503e1 Mon Sep 17 00:00:00 2001 From: uramer Date: Mon, 12 Feb 2024 20:28:56 +0100 Subject: [PATCH] Fix crash when passing a non-callback table to a callback argument --- components/lua/asyncpackage.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/lua/asyncpackage.cpp b/components/lua/asyncpackage.cpp index 8316ab2cde..863680ae9e 100644 --- a/components/lua/asyncpackage.cpp +++ b/components/lua/asyncpackage.cpp @@ -24,7 +24,11 @@ namespace LuaUtil Callback Callback::fromLua(const sol::table& t) { - return Callback{ t.raw_get(1), t.raw_get(2).mHiddenData }; + const sol::object& function = t.get_or(1, sol::nil); + const sol::object& asyncPackageId = t.get_or(2, sol::nil); + if (!function.is() || !asyncPackageId.is()) + throw std::domain_error("Expected an async:callback, received a table"); + return Callback{ function.as(), asyncPackageId.as().mHiddenData }; } bool Callback::isLuaCallback(const sol::object& t)