Digital | 14 Aug 2012 01:29

Passing lua state in struct in c

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.


Gmane