[JW Lua] Stack traceback

Jan Angermüller jan at angermueller.com
Wed Mar 30 11:35:21 CEST 2016


That's a good idea, Thomas !

Am 30.03.2016 um 04:55 schrieb Thomas Weber:
> Standalone Lua usually provides a detailed stack traceback on errors, e.g. for a script like this:
>
>
>      local function a(t)
>        t[1][1] = 1
>      end
>
>      local function b(t)
>        a(t)
>      end
>
>      local function c(t)
>        b(t)
>      end
>
>      c{}
>
>
> the following error is reported:
>
>
>      lua: test.lua:2: attempt to index field '?' (a nil value)
>      stack traceback:
>          test.lua:2: in function 'a'
>          test.lua:6: in function 'b'
>          test.lua:10: in function 'c'
>          test.lua:13: in main chunk
>          [C]: in ?
>
>
> However, JWLua only reports:
>
>
>      E:\tmp\.\test.lua:2: attempt to index field '?' (a nil value)
>
>
> However, the full stack traceback can be displayed with the help of xpcall() and an appropriate message handler:
>
>
>      local function a(t)
>        t[1][1] = 1
>      end
>
>      local function b(t)
>        a(t)
>      end
>
>      local function c(t)
>        b(t)
>      end
>
>      local function msgh(message)
>        print(debug.traceback(message, 2))
>      end
>
>      xpcall(c, msgh, {})
>
>
> Now, JWLua's output pane displays (with mangled line breaks, however):
>
>
>      Running [test.lua] ======>
>      E:\tmp\.\test.lua:2: attempt to index field '?' (a nil value)
>      stack traceback:
>          E:\tmp\.\test.lua:2: in function 'a'
>          E:\tmp\.\test.lua:6: in function 'b'
>          E:\tmp\.\test.lua:10: in function <E:\tmp\.\test.lua:9>
>          [C]: in function 'xpcall'
>          E:\tmp\.\test.lua:17: in main chunk
>      <======= [test.lua] succeeded (Processing time: 0.001 s).
>
>
> Ideally, the stack traceback info would be provided by default without the need to wrap each script into a function and executing it using xpcall() and a message handler.  Presumably, this would be possible on the C/C++ side by a combination of lua_load() and lua_pcall().
>
> _______________________________________________
> JWLua mailing list
> JWLua at jwmusic.nu
> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>





More information about the JWLua mailing list