[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: Marc Balmer <marc@...>
- Date: Fri, 25 Mar 2011 08:54:04 +0100
Am 24.03.2011 um 23:28 schrieb Daurnimator <quae@daurnimator.com>:
> 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);
> }
>
>
yes. this _is_ wrong.
check the size of a char*...
> Daurnimator.
>