[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Question about Lua 5.0.2 standalone interpreter error message
- From: Rici Lake <lua@...>
- Date: Tue, 26 Dec 2006 17:49:19 -0500
On 26-Dec-06, at 4:45 PM, Tom Bates wrote:
I’ve found that with only the Lua libraries base, string, and table
loaded, an improper reference to a function such as io.write causes
the standalone interpreter to just echo “error in error handling”.
This is both on the prototype hardware and also on the PC using Visual
Studio 6.
(1) Is this expected behavior?
It's what I would expect, if using the standalone interpreter modified
to not load the debug library.
(2) Is the debug library essential?
The debug library is essential to the proper functioning of the
standalone interpreter, if you include the presentation of backtraces
as part of the proper functioning of the standalone interpreter.
No library is essential to the proper functioning of core Lua. That is
to say:
1) Any valid Lua program can be compiled to byte code without the use
of any library
2) The Lua VM can execute byte code without the use of any library,
unless the byte code itself requires that library to be present (by
directly referencing the library or, in the case of the base library, a
function in the base library).
I suspect that that is not the answer you're looking for. If you want
to write a program which embeds Lua, and you'd like that environment to
be able to generate reasonable back traces, you'll need some function
which resembles debug.traceback.
The easiest way to get that function is to copy the code from the debug
library. It's the function called db_errorfb. In 5.1.1, it's at line
318 of ldblib.c. That function will work perfectly well without the
rest of ldblib.c, (although in 5.1.1 it uses the trivial function
getthread()). Moreover, it does not need to be exposed to the Lua
environment in order to work properly. If you do not wish to include
the debug library in an application -- and there are many reasons not
to do so, particularly if the scripts are not trusted -- then you can
simply use the C code from ldblib.c
I'm personally of the opinion that db_errorfb should be part of
lauxlib.c rather than buried in the debug library, precisely because it
would be easier to integrate into an embedding application, but it's
easy enough to copy, or to rewrite according to need.
Hope that helps.