lua-users home
lua-l archive

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

> >> "getargs" needs access to argv, which only lua.c has.
> >
> >??? Surely getargs is passed argv, so it can quite happily be in a library!
> >getopts works this way. Am I missing something?
> As you know, a library function in Lua is a function of the form
> 	static int f (lua_State *L) { ... }
> which is then registered in Lua.
> This means that you cannot send argv to f directly.
> So, argv must either be available as a global variable or as an upvale,
> as lua.c does for l_getargs with register_getargs. In any case, whoever
> opens the library needs to give access to argv, either by copying it to
> a global variable or by pushing it as an upvalue. It seems to me that
> only main can do that.

True, main has to cooperate.

-- | competent, a.  underpromoted