Summary: Print code listing on errors in lua script (when
                 Project: Freeciv
            Submitted by: englabenny
            Submitted on: lördag 2010-03-13 den 20:32
                Category: None
                Priority: 5 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: 



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
stack traceback:
        [string "script.code"]:47: in function <[string "script.code"]:46>

            44: end
            46: function turn_callback(turn, year)
        --> 47:         signal.stuff()
            48: end
            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.

See also 


Reply to this item at:


  Meddelandet skickades via/av Gna!

Freeciv-dev mailing list

Reply via email to