lua-users home
lua-l archive

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

I have had an idea for a small and simple addition to Lua that I thought I
would share with the list. I think Lua's error messages should each have a
unique identifying number that is printed out along with the message. The
messages should also be listed in the Lua manual in numerical order of
their ID numbers. My reasoning is as follows:-

- We expect Lua to be embedded in devices like the Lua microwave oven that
occasionally gets mentioned here. These devices generally have no capacity
for textual output. However, it might be possible to program them to cough
out "E : 14", or something similar, on a 7-segment LED display when an
error occurs (by modifying the error output routine). If there was a
standard set of error numbers, it would be easy for developers to keep a
list of the complete error messages on paper and look them up when

- I think the Lua manual or man page says somewhere that "error messages
are self explanatory". This is generally true, but not if you are a
beginning programmer or you can't read English very well. With numbered
error messages, it is relatively easy for a teacher (or someone with
better English/programming skills) to produce an ordered paper sheet of
messages along with their translation or further explanation of what the
message really means. For example, "unfinished string near xxx" is better
described to a beginner as "you probably forgot to close the quotes".
Although you CAN do this even without error numbers, it is tedious to have
to look through the whole list to find your error. With the messages in
numerical order, it is easy - you could even have a program on the
computer which prints out the appropriate message when supplied with an
error number.

Currently, the error message strings are scattered throughout the Lua code
wherever the error report routine is called. A further refinement to the
error numbering idea would be to extract all the messages out into their
own source file. They could then be referenced in the code by macros or by
keeping them in an array of strings and referring to them by their index.
With this arrangement, a semi-competent C programmer could modify the
error strings to translate them into French or any other language. And if
memory is tight, you could even delete most of the error message to just
leave the error number part and save a small amount of memory (could be
about 200-300 bytes or about 1% of the footprint of the minimal
parser-free embedded Lua?)

I know this wouldn't make a big difference to Lua's usefulness but I just
thought it was worth suggesting. Perhaps it would be more difficult to
implement than I think.