[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to pass arguments to argv function effectively in Lua C API
- From: Daurnimator <quae@...>
- Date: Fri, 25 Mar 2011 09:28:08 +1100
On 25 March 2011 03:48, Jerome Vuarand <jerome.vuarand@gmail.com> wrote:
> nargs = lua_gettop(L);
> argv = (const char**)lua_newuserdata(L, nargs * sizeof(const char*));
> argvlen = (size_t*)lua_newuserdata(L, nargs * sizeof(size_t));
> for (i=0; i<nargs; ++i)
> {
> argv[i] = luaL_checklstring(L, i + 1, &argvlen[i]);
> }
>
Is there something wrong with
int params = lua_gettop(L);
char **argv = malloc(params);
int i;
for (i=1;i<=params;i++) {
argv[i-1]=luaL_checkstring(L,i);
}
Daurnimator.