lua-users home
lua-l archive

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


On Wed, Dec 4, 2013 at 6:16 PM, Philipp Janda <siffiejoe@gmx.net> wrote:
Am 05.12.2013 00:04 schröbte Marc Lepage:

Ah, luaL_checkoption, I knew I had seen that somewhere.

I see it used here:
http://www.lua.org/source/5.1/lbaselib.c.html#luaB_collectgarbage

I can see it's fairly convenient. However in this case, collectgarbage
probably isn't (or at least shouldn't) be called a lot. For functions that
are called a lot, would it be more efficient to pre-create the table of
strings/values for lookup?

Quite possibly, but there's only one way to find out ...
You might also be interested in this[1] thread.

  [1]: http://lua-users.org/lists/lua-l/2012-01/msg00396.html


Philipp



Hey thanks, that thread is exactly along the lines of what I am trying to do and what I was interested in.

I was particularly wondering about interning strings and using the pointers for comparison, which I see is mentioned in the thread. I thought of that but the docs seemed to indicate that the string must be kept on the stack for the pointer to remain valid. The thread confirms this, though it says you're probably OK so long as the string remains referenced and no GC occurs.

I guess I'd still be looping (or if-else-if-ing) over a list of pointers for which to compare, if I can't statically embed that dispatch as a switch statement (the pointers vary at runtime). Better than a strcmp, but now I'm thinking a table of string-to-integer is probably going to be best.

Marc