lua-users home
lua-l archive

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


 On 12.10.2010 21:27, Mark Hamburg wrote:
Note that this does not work if you have multiple Lua universes since the string will have different identities in different universes.

Yet, the idea is still applicable, but with strcmp. It will speed things up for one universe due to matching pointers and work as usual comparison in others.

static int some_c_function (lua_State *L)
{
    if (lua_gettop (L) != 1) return 0;
    const char *arg = lua_tostring (L, 1);
    if (strcmp(arg, strconst_rgba)) {
        lua_pushnumber (L, 1);
        return 1;
    } else if (strcmp(arg, strconst_rgb)) {
        lua_pushnumber (L, 1);
        return 1;
    } else ....
    return 0;
}


--
Best regards,
Sergey Rozhenko                 mailto:sergroj@mail.ru