[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Possible enhancements for Lua 5.2
- From: Rebel Neurofog <rebelneurofog@...>
- Date: Sun, 26 Jun 2011 19:53:50 +0400
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.