lua-users home
lua-l archive

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


>That's why we wanted that functionality for yindo as well. Why download code 
>across the net to memory and then have to put it in a temp file, read it back into
>memory and delete the file?

Perhaps we're wrong in this "hand-holding" and it would be better to let
dostring run precompiled code. The rationale is that Lua code can never cash
the host program (bad use of the C API, can of course).  If dostring accepted
precompiled code, it might be possible to crash the host by feeding dostring
with malicious code, created on the fly in Lua, although I almost sure
that badly built precompiled code is flagged; the only problems would be
runtime errors, which have been discussed here in previous messages, and are
hard to handle.

Anyway, it's simple to change dostring to allow precompiled code: Just remove
the two lines marked below from lbaselib.c:

 static int luaB_dostring (lua_State *L) {
   int oldtop = lua_gettop(L);
   size_t l;
   const char *s = luaL_check_lstr(L, 1, &l);
|  if (*s == '\27')  /* binary files start with ESC... */
|    lua_error(L, "`dostring' cannot run pre-compiled code");
   return passresults(L, lua_dobuffer(L, s, l, luaL_opt_string(L, 2, s)), oldtop)
 ;
}

Or write a luaB_dobuffer and export it to Lua.
--lhf