[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: Alexander Gladysh <agladysh@...>
- Date: Thu, 24 Mar 2011 14:49:30 +0300
On Thu, Mar 24, 2011 at 09:02, Sean Conner <sean@conman.org> wrote:
> It was thus said that the Great Alexander Gladysh once stated:
>> I want to bind to Lua a third-party argv function, taking a list of
>> strings as input:
>>
>> foo * bar(baz * pSelf, int argc, char ** argv, size_t * argvlen);
>
> There are two approaches---one is to pass in a series of strings, the
> other, an array of strings. So, you have:
> result1 = obj:bar("one","two","three","four")
> result2 = obj:bar { "one" , "two" , "three" , "four" }
> Okay, so let's handle both:
<...>
> You might need to adjust it a bit to fit your needs, but that's about how
> I would do it.
Thanks. This is more or less what I've implemented (see the links in
the original post) — except for the table argument approach, which, I
believe, is not much needed in this case.
But I would like to get rid of allocations (note that I also have to
fill arvlen array with string lengths). So, Luiz's idea about
pre-allocated arrays is appealing. The only question is what maximum
array length to hardcode.
Alexander.