lua-users home
lua-l archive

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


> Out of the two implementations I sketched out, would there be any
> significant performance difference between them? Basically I am
> interested in the relative efficiency of passing strings vs numbers from
> lua to C.

>From Lua to C, they have the same perfomance. From C to Lua, strings
have to hashed, even if they already exist in Lua. If you already have
a string as a Lua value and you want to pass it back to Lua, then you
can use lua_pushvalue and avoid the hash.

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.