Summary: Print code listing on errors in lua script (when
Submitted by: englabenny
Submitted on: lördag 2010-03-13 den 20:32
Priority: 5 - Normal
Assigned to: None
Discussion Lock: Any
When we have the script code string available, use it on error in
script_call so we can show the lines where the error was encountered.
If there is a lua error in script_callback_invoke, when we call an
event callback, we assume the callback is defined in the section
script.code. If we always use the source code from script.code here,
we get the exact lines of the code where the error was encountered in
the error message.
This change will have strange effects if the user defines callbacks
inside script.vars, because we will print the correct error message
for the error, but try to display code from the corresponding line
numbers in script.code. However this should never happen.
With this change, the user/developer can see the lines of code
surrounding the error immediately, and often gets an arrow pointing
exactly at the line containing the error.
The effect is very nice for the user/developer:
1: lua error:
[string "script.code"]:47: attempt to call field 'stuff' (a nil
[string "script.code"]:47: in function <[string "script.code"]:46>
46: function turn_callback(turn, year)
--> 47: signal.stuff()
50: signal.connect("turn_started", "turn_callback")
Now we are talking error messages! Quite a step up, all taken together, from
the "error in error reporting" we had before.
I hope this can go into 2.2 and trunk.
Reply to this item at:
Meddelandet skickades via/av Gna!
Freeciv-dev mailing list