lua-users home
lua-l archive

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

At present (from `man lua`):

       -l name
              execute  the equivalent of name=require('name') before executing


       -l [loaded=]name
              execute  the equivalent of loaded=require('name'), or if
not supplied,
              name=require('name') before executing script.

Inspired by the fact that "lua -l pl.stringio" creates `_G.["pl.stringio"]` and
Steve has promised more of the same. (Yes, I know I can solve that
problem with "-e".)

Patch to lua.c attached. Compiles warning-free as a Lua 5.2.4 patch but
gives a warning for incompatible types on 5.3.4 that I can't fix. Still works,
<   lua_getglobal(L, "require");
<   lua_pushstring(L, name);
>   char *eq = strchr(name,'=');
>   lua_getglobal(L, "require");  
>   if (eq==name) lua_pushstring(L, name);
>   else lua_pushstring(L, eq+1);
<   if (status == LUA_OK)
<     lua_setglobal(L, name);  /* global[name] = require return */
>   if (status == LUA_OK) {
>     if (eq==name) lua_setglobal(L, name);  /* global[name] = require return */
>     else lua_setglobal(L, strndup(name,eq-name));       
>   }