Pazyryk
Deity
- Joined
- Jun 13, 2008
- Messages
- 3,584
Not only can you have reliable Lua error reporting (which is broken in base Civ5; see here), but when you do get an error traceback, you can have function name and full file path that is not truncated into uselessness.
Here's an example error report:
The first line is truncated because it is from the base error reporting system. But the rest is generated by my own Lua traceback function, so it can give full path (or any other info from the debug library if you care to edit it).
Basically, C++ calls Lua (via GameEvents or Events) and everything downstream of that is a Lua chunk (until that last Lua function reaches it end). If there is an error anywhere in that chunk then all the Lua stops and it goes back to C++, which can either give you an error message (which it does if it was from Events) or tell you nothing at all (which it does if it was called from GameEvents). Even for Events, the error printing is out of your control and you get the truncated (uninformative) path name.
To get around both issues, I've implemented my own Lua Error Handler. It uses xpcall to "contain" any downstream error and trigger my own Traceback.lua function.
See details here.
Here's an example error report:
Code:
EaMain: [string "C:\Users\Pazyryk\Documents\My Gam..."]:32: attempt to index global 'nonexistentObject' (a nil value)
EaMain: 2: BuggeredFunction C:\Users\Pazyryk\Documents\My Games\Sid Meier's Civilization 5\MODS\Ea II The Ageless and the Divine (v 5)\Utilities\EaDebugUtils.lua: 32
EaMain: 3: nil C:\Users\Pazyryk\Documents\My Games\Sid Meier's Civilization 5\MODS\Ea II The Ageless and the Divine (v 5)\EaMain\EaPrereqs.lua: 107
EaMain: 4: =(tail call): -1
EaMain: 5: C function
EaMain: 6: nil C:\Users\Pazyryk\Documents\My Games\Sid Meier's Civilization 5\MODS\Ea II The Ageless and the Divine (v 5)\EaMain/EaMain.lua: 335
EaMain: 7: =(tail call): -1
Basically, C++ calls Lua (via GameEvents or Events) and everything downstream of that is a Lua chunk (until that last Lua function reaches it end). If there is an error anywhere in that chunk then all the Lua stops and it goes back to C++, which can either give you an error message (which it does if it was from Events) or tell you nothing at all (which it does if it was called from GameEvents). Even for Events, the error printing is out of your control and you get the truncated (uninformative) path name.
To get around both issues, I've implemented my own Lua Error Handler. It uses xpcall to "contain" any downstream error and trigger my own Traceback.lua function.
See details here.