lua-users home
lua-l archive

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


Another minor update to my RPMs, this time a very slight divergence from
the official sources to correct an annoyance: in my Lua libraries (on
which more soon!) I use error() to implement a function die(). The idea is
that if you want to, you can catch it; otherwise you can just let it be
caught by the lua standalone program.

In Lua 4, if you call error(), then lua exits with no message. Lua 5
complains that error expects an argument. OK, so try calling error(false)
(i.e. a non-string value). This nearly works: you don't get the stack
backtrace in this case, but you get a message saying "(error with no
message)". Sigh.

To cope with this I added a few lines to lua.c so that when it
gets a call to error with no message, it does the following:

1. It reads the global variable LUA_NO_ERROR.
2a. If the variable is not a string, it displays "(error with no message)"
as before. This keeps the default case the same.
2b. If the variable is the empty string, it displays no message (what
I want!).
2c. If the variable is some other string, it displays that message.

I'd be interested to know if anyone else has views on this (or if there's
already a neat way around it that I've missed).

Anyway, come and get the goodies at:

http://www.mupsych.org/~rrt/Lua

-- 
http://www.mupsych.org/~rrt/ | maximiste, n.  pessimiste (Roux)