lua-users home
lua-l archive

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

I think my original point might have been misinterpreted during this

To clarify, we SHOULDN'T remove the existing error messages from Lua, but
merely add an identifying number to them. For example:-

	unfinished string near 'xxx'

...might become

	unfinished string near 'xxx' (#14)

.or something similar (this only adds a few bytes to the message in the
normal case). You then ALSO have a list of error messages in the manual in
numerical order, so looking through the list you would find something

1 - stack overflow
2 - cannot yield a C function
14 - unfinished string near 'xxx'

...and so on.

This makes it easy for anyone to look up a message in the list and be sure
they have got the right one. There are at least 33 errors, so you wouldn't
want to look through the list exhaustively each time an error occurred.
Using alphabetical order is not a good idea because some messages look
very similar while others like "xxx too new", etc actually BEGIN with the
changeable part. I could imagine someone getting confused between "stack
overflow" and "C stack overflow", for instance, if there was no unique ID

Now, beginners and people with poor English could easily have a list
prepared for them by a teacher or another programmer with explanatory
notes added for each error message. You could even post these lists on the
Lua website or wiki as a useful resource. Preparing such a list would
probably be a simple matter of copy/paste from the manual's error table
into a text document and then typing the new notes in between.

Another advantage of the numbers is that they can be used in cases where a
device's display capabilities allow for numbers but not text (very common
with 7-segment LEDs on clocks, microwaves, etc). Obviously, embedders
could invent their own numbers but it is better for them if this task has
already been done by someone else.

But while we are looking at error messages, it would also be a good idea
to take the error strings from the C source files and put them into their
own header file called "lerrmsg.h". They would be kept in numerical order
in this file and referenced by macros. So the file would look something

/* Double-digit numbers recommended! */
#define LERR01 "stack overflow (#01)"
#define LERR02 "cannot yield a C function (#02)"

...etc. Currently these strings appear directly in the calls to
luaG_runerror wherever they occur in the code. Having the messages all in
one place is good source code organisation, but it also has the advantage
that the text can be adapted easily without searching through several
source files. These messages could be translated into a language other
than English for localisation or could be removed altogether to save about
900 bytes of space in the VM. As far as I can tell, using macros for this
results in exactly the same object code so there is no slowdown in the
normal, unmodified source.

All this just seems to me to be a very simple way to make Lua slightly
more attractive to embedders, beginning programmers and people who don't
read English very well.