summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-09-03 12:28:25 -0400
committerNat Goodspeed <nat@lindenlab.com>2024-09-03 12:28:25 -0400
commit9dc916bfcafd43890be20623d359be82e84f73ac (patch)
treef9332c30c29643be8f74ee97215b4519c5f9752c
parent1101ed699a0c3c23c0bb11267d390febfdc02409 (diff)
In lua_what() and lua_stack(), try to report a function's name.
-rw-r--r--indra/llcommon/lua_function.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/indra/llcommon/lua_function.cpp b/indra/llcommon/lua_function.cpp
index da88f57a5b..67ca29c689 100644
--- a/indra/llcommon/lua_function.cpp
+++ b/indra/llcommon/lua_function.cpp
@@ -567,6 +567,7 @@ void replace_entry(lua_State* L, int index,
int lua_metapairs(lua_State* L)
{
+// LuaLog debug(L, "lua_metapairs()");
// pairs(obj): object is at index 1
// How many args were we passed?
int args = lua_gettop(L);
@@ -591,6 +592,7 @@ int lua_metapairs(lua_State* L)
int lua_metaipairs(lua_State* L)
{
+// LuaLog debug(L, "lua_metaipairs()");
// ipairs(obj): object is at index 1
// How many args were we passed?
int args = lua_gettop(L);
@@ -633,9 +635,10 @@ int lua_metaipairs(lua_State* L)
int lua_metaipair(lua_State* L)
{
+// LuaLog debug(L, "lua_metaipair()");
// called with (obj, previous-index)
// increment previous-index for this call
- lua_Integer i = luaL_checkinteger(L, 2) + 1;
+ lua_Integer i = luaL_optinteger(L, 2, 0) + 1;
lua_pop(L, 1);
// stack: obj
lua_pushinteger(L, i);
@@ -1523,6 +1526,31 @@ std::ostream& operator<<(std::ostream& out, const lua_what& self)
out << lua_touserdata(self.L, self.index);
break;
+ case LUA_TFUNCTION:
+ {
+ // Try for the function's name, at the cost of a few more stack
+ // entries.
+ lua_checkdelta(self.L);
+ lluau_checkstack(self.L, 3);
+ lua_getglobal(self.L, "debug");
+ // stack: ..., debug
+ lua_getfield(self.L, -1, "info");
+ // stack: ..., debug, debug.info
+ lua_remove(self.L, -2);
+ // stack: ..., debug.info
+ lua_pushvalue(self.L, self.index);
+ // stack: ..., debug.info, this function
+ lua_pushstring(self.L, "n");
+ // stack: ..., debug.info, this function, "n"
+ // 2 arguments, 1 return value (or error message), no error handler
+ lua_pcall(self.L, 2, 1, 0);
+ // stack: ..., function name (or error) from debug.info()
+ out << "function " << lua_tostdstring(self.L, -1);
+ lua_pop(self.L, 1);
+ // stack: ...
+ break;
+ }
+
default:
// anything else, don't bother trying to report value, just type
out << lua_typename(self.L, lua_type(self.L, self.index));