lua-users home
lua-l archive

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


2011/3/24 Alexander Gladysh <agladysh@gmail.com>:
> On Thu, Mar 24, 2011 at 20:40, Jerome Vuarand <jerome.vuarand@gmail.com> wrote:
>>  lua_replace(L, LUA_ENVIRONINDEX); /* (3) */
>
> This will not work in 5.2 anymore. (Not that I'm that much eager to
> support it, but...)

In 5.2 you have to use upvalues instead. Thankfully, there is a
luaL_register-like function that let you push an array of functions
sharing an upvalue (the module table), which was a little more
complicated to do in 5.1.

>>> 2. What is the best way to handle REDIS_REPLY_STATUS case? Just bite
>>> the bullet and do two string comparisons? Or does anyone see something
>>> more clever?
>
>> So redis gives you a C string ?
>
> Yep.
>
>> Just use it as a key in the module
>> table, which you previously set as all your lua_CFunction-s
>> environment:
>
>> {
>>  const char* redis_result;
>>  ... /* get a value for redis_result */
>>  lua_getfield(L, LUA_ENVIRONINDEX, redis_result);
>>  return 1;
>> }
>
> Looks like that, with some metatable magic, I even can create status
> userdata on demand and not bother with pre-caching it.

This qualifies as premature optimization too ;-)

If you only have a few status codes, the metatable + metamethod
creation may just cost more that pre-caching the values.