[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: lua_parseargs
- From: Nicolas Devillard <ndevilla@...>
- Date: Wed, 24 Jan 2001 14:28:53 +0100 (MET)
Hello to all:
The following snippet is useful to carry over the command-line arguments
you have received into a Lua space. Maybe a useful addition to 4.1?
void lua_parseargs(lua_State * L, int argc, char * argv[])
{
int i ;
/* Create a new table and push it onto the stack */
lua_newtable(L);
/* insert argc keys into table */
for (i=0 ; i<argc ; i++) {
lua_pushstring(L, argv[i]);
lua_rawseti(L, 1, i);
}
/* Set table as global variable 'args' */
lua_setglobal(L, "args");
return ;
}
Cheers
--
Nicolas