lua-users home
lua-l archive

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


> > Does anyone else have view on my wish for:
> > lua_load(), lua_dump() to have an extra parameter that strips the
> > debug symbols?
> 
> For lua_load, yes please, and in the Lua interface as well.  Is it necessary for lua_dump?  Another option might be a strip function for closures (prototypes really).

As I've mentioned earlier [1], it's much simpler to strip at dump time
than at load time. At load time, we have either to read and skip debug
info from the stream or read and save as now and then strip after loading.
The first option complicates the loader. The second option is pretty easy
to implement; luac used to do that:

 static void strip(lua_State* L, Proto* f)
 {
  int i,n=f->sizep;
  luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
  luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
  luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
  f->lineinfo=NULL; f->sizelineinfo=0;
  f->locvars=NULL;  f->sizelocvars=0;
  f->upvalues=NULL; f->sizeupvalues=0;
  f->source=luaS_newliteral(L,"=?");
  for (i=0; i<n; i++) strip(L,f->p[i]);
 }

You may call strip in ldo.c just before returning from f_parser,
or in lundump.c just before returning from LoadFunction, in which
case you may drop the "for".

Anyway, I think the main point here is that adding a flag to the API
complicates it. Do you really want to choose whether or not to strip
debug info at run time?

--lhf

[1] http://lua-users.org/lists/lua-l/2006-04/msg00623.html