On Tue, Apr 9, 2013 at 10:30 PM, Thijs Schreijer <[email protected]>wrote:

> Made the commandline arguments appear. The wrapper code loading the args
> and doing the pcall is here;
> https://github.com/keplerproject/luarocks/blob/master/src/bin/rclauncher.c#L47
>

Ah, I remember this problem from srlua.  It really does need to build a
global 'arg' as well, since something like ldoc does actually use arg.
Sloppy, but very common.

A full solution would also set arg[-1] and arg[0] to sensible values.  Here
is the equivalent function that calls the embedded Lua script from srlua.c

static int pmain(lua_State *L)
{
 int argc=lua_tointeger(L,1);
 char** argv=lua_touserdata(L,2);
 int i;
 const char *name = search_path(argv[0]);
 if (name==NULL) fatal("srlua","cannot locate this executable");

 lua_gc(L,LUA_GCSTOP,0);
 luaL_openlibs(L);
 lua_gc(L,LUA_GCRESTART,0);
 load(L,name);
 lua_createtable(L,argc,1);
 for (i=0; i<argc; i++)
 {
  lua_pushstring(L,argv[i]);
  lua_rawseti(L,-2,i);
 }
 lua_setglobal(L,"arg");
 luaL_checkstack(L,argc,"too many arguments to script");
 for (i=1; i<argc; i++)
 {
  lua_pushstring(L,argv[i]);
 }
 lua_call(L,argc-1,0);
 return 0;
}

(Note that the first loop goes from 0 - these details matter ;))

>
> PS. Did this ever work?
>

I suppose it might have worked with simple tests ;)
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Luarocks-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luarocks-developers

Reply via email to