[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Throwback
- From: Dirk Laurie <dirk.laurie@...>
- Date: Wed, 13 May 2015 08:47:06 +0200
2015-05-13 8:26 GMT+02:00 Gavin Wraith <gavin@wra1th.plus.com>:
> I have been going through the Lua sources trying to understand what
> happens when an error is raised. The difficulty, from my point of
> view, is that the various error functions appear to be simply concatenating
> lots of error messages. But I need an error datatype
>
> typedef struct err {
> char *filename; int linenumber; char *message; } err;
>
AFAIK the Lua core uses the same "lua_error" accessible from the API
which takes an error object (i.e. a string or something with a __tostring
metamethod) as only argument. But "Lua itself only generates errors
whose error object is a string, but programs may generate errors with
any value as the error object." (§2.3)
> I need to extract the requisite filename and linenumber.
That is not part of the error message. It is extracted from the stack
state by the error handler. You can get a non-error version of it by
luaL_where.