lua-users home
lua-l archive

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


On 26/06/2011 12:53, Rebel Neurofog wrote:
I also have all those paranoic thoughts about fast string processing:)
And so I've decided to do this (I didn't compare performance):

After opening Lua state I put table like this into registry:
     lua_newtable (L);
     ADD_NUMERIC_FIELD ("points", GL_POINTS);
     ADD_NUMERIC_FIELD ("lines", GL_LINES);
    ...
     lua_setfield (L, LUA_REGISTRYINDEX, "*prim*");

and in C function I look up for this table like this:

    lua_getfield (L, LUA_REGISTRYINDEX, "*prim*");
    lua_pushvalue (L, -5);
    lua_rawget (L, -2);
    if (!lua_isnumber (L, -1)) return failure ();

At least I don't need to think about strcmp () vs strliteralequal ()
which is declared like
#define strliteralequal(str,literal,n)                                  \
     ((((sizeof ("" literal)/sizeof (char)) - 1) == (n))&&  !memcmp
(("" literal), (str), ((sizeof ("" literal)/sizeof (char)) - 1)))

It includes embedded zeroes during comparison.



But that takes a table lookup for the key...

Cheers,

Andre