lua-users home
lua-l archive

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


> 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;
> }
Good idea, but be careful:
use

if (!strcmp(arg, strconst_rgba)) {

instead

if (strcmp(arg, strconst_rgba)) {

because strcmp () returns 0 on match.


Anyway, one Lua state per thread may be chosen as a design of application.
In this case pthread_key_create () should be used to handle
thread-specific data.