lua-users home
lua-l archive

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


Hi,

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

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

Bye,
     Mike