lua-users home
lua-l archive

Re: How to pass arguments to argv function effectively in Lua C API

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


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.
> 

AltStyle によって変換されたページ (->オリジナル) /