ryobg / JContainers

JSON-based data structures for Papyrus - the TESV Skyrim SE scripting language
MIT License
107 stars 23 forks source link

Better lua error messages #29

Closed RealAntithesis closed 6 years ago

RealAntithesis commented 6 years ago

I've been busy writing some lua code in an attempt to speed up certain parts of my papyrus code. Since I'm still learning lua, this has been, while fun, also somewhat frustrating when trying to track down the exact source of all the error messages printed out to the console. Mostly, these error messages refer to some error in the internal lua files, such as:

Lua error: [string "local args = ...; local jobject = args;return..."]:1: attempt to call field 'findIndex' (a nil value) Lua trace: stack traceback: [C]: in function 'findIndex' [string "local args = ...; local jobject = args;return..."]:1: in function 'func' ...ion/Data/SKSE/Plugins/JCData/InternalLuaScripts/init.lua:202: in function <...ion/Data/SKSE/Plugins/JCData/InternalLuaScripts/init.lua:199>

To my untrained eye, this doesn't really tell me the exact source of the problem - printing out the full text of the lua function that was attempted to be called (i.e. what I put into the JValue.evalLuaObj predicate parameter) would help track down the issue.

ryobg commented 6 years ago

So you mean to add to this error text the string evaluated? I agree that these are a bit mangled. No idea why it is like. Will check what it can be done.

RealAntithesis commented 6 years ago

The error was somewhat useful after all. It was referring to my lua function "AH_Hotkeys.FindIndex" in my init.lua file, which I had capitalised from "findIndex" to "FindIndex", but didn't change the evalLuaObject parameter to match. I didn't pick up at the time that lua is apparently case sensitive. However, it would have been helpful to have a somewhat less cryptic error (I understand that, in this case, the interpreter wouldn't have been able to know what function I was attempting to refer to in my init.lua file).

ryobg commented 6 years ago
Lua error: [string "local args = ...; local jobject = args;return..."]:1: attempt to index global 'bit3' (a nil value)
Lua trace: stack traceback:
        [C]: in function '__index'
        [string "local args = ...; local jobject = args;return..."]:1: in function 'func'
        ...bug/Data/SKSE/Plugins/JCData/InternalLuaScripts/init.lua:203: in function <...bug/Data/SKSE/Plugins/JCData/InternalLuaScripts/init.lua:200>
Lua string: return bit3.bxor (8, 2, 10)

An example error. The last row Lua string: ... is the new record.