r/lua • u/SkyyySi • May 25 '25
Is there a way to push custom debug information from the Lua/C-API?
I'd like to provide Lua with additional debug info when interacting with it from C. I want to push __func__, __FILE__ and __LINE__ as the debug.getinfo() table fileds name, source/short_src and currentline, respectively. Is there an intended way to do this, would it require touching private APIs, or is it not possible at all?
I'm mainly targeting LuaJIT, but something compatible with all versions (PUC Lua 5.1 to 5.4 as well as LuaJIT) would be best.
3
Upvotes
3
u/Motor_Let_6190 May 25 '25
Pretty much as intended : https://lua.org/pil/23.1.html
And you can supercharge with user defined types in C, if you want to have types dedicated to debugging : https://lua.org/pil/28.html
1
u/xoner2 May 27 '25
You can use file, line macros when calling luaL_error. Or push into a stack in the registry.
0
u/[deleted] May 25 '25
[deleted] — view deleted comment