[lua] Add traceback info when a doc object is deleted and we try to use it

A reference to a doc object (Sprite, Layer, Cel, etc.) is done through
its ID in the scripting engine, when we try to access it from a script
that element might be already deleted. Previously we displayed the a
message like "Using a nil 'Cel' object". With this change we show the
traceback and a "Tried to access a deleted 'Cel'" message.
This commit is contained in:
David Capello 2023-08-03 20:45:44 -03:00
parent 741cd31fdd
commit 558ff54cb0

View File

@ -41,7 +41,11 @@ template <typename T> T* check_docobj(lua_State* L, T* obj) {
if (obj)
return obj;
else {
luaL_error(L, "Using a nil '%s' object", get_mtname<T>());
luaL_traceback(L, L, nullptr, 1);
const char* traceback = lua_tostring(L, -1);
luaL_error(L, "%s: Tried to access a deleted '%s'",
traceback ? traceback: "",
get_mtname<T>());
ASSERT(false); // unreachable code
return nullptr;
}