[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C string pointers to Lua
- From: Rebel Neurofog <rebelneurofog@...>
- Date: Fri, 15 Oct 2010 09:04:01 +0400
> 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.