lua-users home
lua-l archive

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


On Nov 16, 2004, at 7:51 PM, Adrian Sietsma wrote:
I would dearly like to have the debug info contain the source length, as discussed here some months ago. It would be a real help for some stuff i wish to do, particularly when parsing user-supplied scripts.


IIRC, I was the one who made that request a few months ago... As it turns out, its not that difficult to change the lua distribution to include this ability...

If you grep for "lineDefined" and "linedefined" (note: those differ only in capitalization; they are the relevant field names in the Proto and lua_Debug structs), you'll see the places in the code that need a change.

I simply added a "lineDefinedEnd" field in both lua_Debug and Proto.The only tricky part is to make sure the lua parser fills in the lineDefinedEnd field in the Proto struct. This small change seems to be working for me in lparser.c:

This is taken from the Lua 5.0 source code; I haven't yet looked at 5.1.

static void body (LexState *ls, expdesc *e, int needself, int line) {
/* body -> `(' parlist `)' chunk END */
FuncState new_fs;
open_func(ls, &new_fs);
new_fs.f->lineDefined = line;
check(ls, '(');
if (needself)
create_local(ls, "self");
parlist(ls);
check(ls, ')');
chunk(ls);
check_match(ls, TK_END, TK_FUNCTION, line);

#if NONSTANDARD_LUA_EXTENSIONS
// remember the line that the function ended on (tgogolin Feb 19 2004)
new_fs.f->lineDefinedEnd = ls->lastline;
#endif

close_func(ls);
pushclosure(ls, &new_fs, e);
}


--
Tim Gogolin