[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: String parameters when calling C from Lua
- From: Mike Pall <mikelu-0605@...>
- Date: Fri, 19 May 2006 13:10:28 +0200
Luiz Henrique de Figueiredo wrote:
> Back to your question, I think the main point is what you want to do
> with strings in C. If you want to make decisions based on them and
> have to strcmp them, then it'd be easier for C to do a switch on
> integers. The Lua standard libraries convert strings to numbers for that;
> see luaL_checkoption.
Ahemm. luaL_checkoption does a linear loop with lots of strcmps.
This is ok only for very few elements or in non-performance
For more elements use a private table in an upvalue of a C
function. Add the string keys plus target values. Either numbers
or lightuserdata may be suitable.
Oh, and another hint: don't attempt to outsmart the method lookup
logic (a table of functions indexed by strings) with the above
plus a switch statement. This is unlikely to yield better