lua-users home
lua-l archive

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

So, I may try with another delimiter, but in general, I would still stick to the idea to add additional file information into the source name.

Patching the error function might be the better idea any way. I then also can structure my output better. For old project, it would still be a compatible solution, just the error output wont be as nice. But that is not a problem, the error output is, so far, only interpreted by humans.


On 05/03/2013 11:52 AM, Jean-Luc Jumpertz wrote:
Le 3 mai 2013 à 10:48, Thomas Jericke <> a écrit :
I don't want to have the hash or timestamp making my error messages unreadable
One point I forgot to mention in my previous post is that keeping the file version information in the error string created by Lua allows to determine which version of a source file caused the error.
Then the post-processing of the error string permits to transform the message into something more user-friendly.
That's why IMHO the insertion of '\0' characters in the middle of the source file name isn't a good strategy...


Le 3 mai 2013 à 11:22, Jean-Luc Jumpertz <> a écrit :

I could alternatively  patch the error message function of Lua
That's actually what I did for keeping the error messages readable (and to redirect them more easily to my IDE).
The simplest way I found for doing so is to redefine macros luai_writestring and luai_writeline in luaconf.h

In my version of luaconf.h I replaced

if defined(LUA_LIB) || defined(lua_c)
#include <stdio.h>
#define luai_writestring(s,l)	fwrite((s), sizeof(char), (l), stdout)
#define luai_writeline()	(luai_writestring("\n", 1), fflush(stdout))


extern void CIMLuaPrintAppendString (void *L, const char* s);
extern void CIMLuaPrintLine (void *L);
#define luai_writestring(s,l)	CIMLuaPrintAppendString(L,s)
#define luai_writeline()	CIMLuaPrintLine (L)

#elif defined(LUA_LIB) || defined(lua_c)
#include <stdio.h>
#define luai_writestring(s,l)	fwrite((s), sizeof(char), (l), stdout)
#define luai_writeline()	(luai_writestring("\n", 1), fflush(stdout))

where CIMLuaPrintAppendString and  CIMLuaPrintLine are the external C functions where do the specific processing of the error string (easy to recognize with a regexp).


Le 3 mai 2013 à 10:48, Thomas Jericke <> a écrit :

Hi Jean-Luc
As I see it, you did the same as I want to do, using the sourcename to store the extra information. I just add another twist to it. Instead of '@' I would use a '\0' as delimiter. My major concern is, that I don't want to have the hash or timestamp making my error messages unreadable. With the \0 I could hide the hash. I could alternatively  patch the error message function of Lua and use another delimiter. Maybe that would be better, but I would still risk that the hash is visible if I don't patch all function that print out the source name.

Probably the best thing, is to test a few different approaches and compare the results.



On 05/03/2013 09:47 AM, Jean-Luc Jumpertz wrote:
Hi Thomas,

I had the same concern of differentiating several versions of a source file in the interpreter and  solved it without changing Lua's internals, by taking advantage of the fact that you can pass an arbitrary string as the source name of a loaded Lua code chunk (e.g. in the "source" parameter of Lua function "load" or in the "name" parameter of the C function "luaL_loadbuffer").

Using these methods, it is easy to write a custom load-file function in which you define the source name that fits your needs. In my implementation, I concatenate the file name and modification date like "mysourcefile.lua@12345678" - as this allows the sorting by time of the loaded versions - but the same can be done with a hash of the source code.


Le 3 mai 2013 à 08:40, Thomas Jericke <> a écrit :

Hi all

I am currently improving our editor/debugger (just finished painting globals purple :-) ) and my current task is to improve the source lookup.

Currently the lookup is based on the sourcename alone. This is usually OK but we have several cases where it is possible that different versions of the same file is loaded in the interpreter. Or the source in the interpreter is very old, our application can literally run for months. The most obvious case of a source/interpreter conflict is when a programmer mode changes/fixes without restarting the program (= restarting the machine).

So what I like to do is to store a hash of the source file which is then provided with the lua_Debug information. Once I am debugging a file I can use the hash to double check if the file that the editor is showing is really the one that the interpreter runs. I am then able to warn the user or show a "source not found" error.

As I see it I need to add and receive the hash at exactly the same places as the source-name that would be in the "Proto" struct field "source". Now what I thought, as the two always go together, I could actually store the hash inside the source variable. I would than have the advantage of being backwards and forward compatible that is: I could load compiled Lua code from a patched parser into an unpatched interpreter, and I could load Lua code from an unpatched parser into a patched interpreter.

My idea is, as a Lua string may have \0 within the string, I could just add the hash behind the name like:

As the length of the string is stored, my patched interpreter will find out if there is a hash or not, on the other hand a old interpreter will simply return the char* pointer of to the name, which is from a C/C++ point of view still the same as before.

It will break the comparability of old interpreters using the Lua debug library (not the C debug API), but we are not using the Lua debug library anyway only the API.

So what do you think? Are there any incompatibilities I don't see? I am open to any input.


Indel AG
Thomas Jericke - Management
Tuefiwis 26
CH-8332 Russikon

Tel.: +41 44 956 20 00

iDev replaces IMD as the official IDE for Indel embedded programming.