lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I've followed the example in rings in my projects:
http://www.keplerproject.org/rings/ .  They use debug.traceback, which
gives really nice error feedback.

wes

On Fri, Jul 24, 2009 at 4:05 PM, John Dunn<John_Dunn@qscaudio.com> wrote:
> I have 2 questions about error reporting back to the user.
>
> The first is pretty simple - are there any examples as to how to use the
> optional errorfunc argument to lua_pcall? I'd like to remove some of the
> error string but I can't find any examples on how to accomplish that
> with a custom errorfunc.
>
> The second question is a little more complicated. I load a user defined
> script, in which the user can assign callback functions to objects.
> Something like
>
>        button:AddEventHandler(function() ... end)
>
> but since I wanted a more 'Property' like interface for my users, I
> assigned a __newindex() to my metatable
>
>        local mt, methods = ...
>                function mt:__newindex(k, v)
>                        if k == 'EventHandler' then
>                                self: AddEventHandler (v)  -- this is
> line 47 in my initialization script
>                        end
>                end
>
> so my users can use the following syntax
>
>        button.EventHandler = function() ... end
>
> That all works perfectly fine, except if AddEventHandler raises an
> error. In that case the line number reported is the line number of the
> mt:__newindex() ( which I instantiate behind the scenes and is always
> 47! ), not the line number in the user script. I'd like to report the
> error where the user called .EventHandler, not the internal __newindex
> call - any idea how I might go about going that?
>
> John
>
>