lua-users home
lua-l archive

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


How can I pass a lua state in a struct to a function or thread in c/c++?

I tried:

//----------------------
lua_State *L;

struct sargs {
 lua_State *L;
 char *arg2;
};

void *runlua(void *arg)
{
char *dat;
struct sargs *args = (struct sargs*)arg;
lua_State *L = (lua_State *) args->L;
dat = args->arg2;
return NULL;
}

int main()
{
// Init the regular lua stuff:

struct sargs pargs;
pargs.L = L;
pargs.arg2 = "pass data";

return 0;
}

But with that I am unable to retrieve the lua state. Or through a created thread passing the struct as argument.