First of all, but if I rewrite entirely the MQTT stack, I have to keep my current implementation where Paho library spawn a new C thread to handle incoming messages. The question now is how to get the new Lua_stat ?
But, as per this wiki, I'll have to create my own locking function, right ?
- I noticed also lua_newstate()
but I wasn't able to determine if global variables are still accessible or not.
So, all in all, my new code may looks like something like :
struct _context {
lua_State *L;
... other context stuffs, bla bla ...
};
int msgarrived(void *actx, char *topic, int tlen, MQTTClient_message *msg){
struct _context *ctx = (struct _context *)actx; // to avoid zillion of casting
...
lua_pushnil(ctx->L); // push nil in the alternate Lua stack
...
}
void myinit( lua_State *L){
struct _context ctx; // in fact, it will not be a stack object, but it's only an example
MQTTClient_setCallbacks( client, &ctx, connlost, msgarrived, NULL);
}
Best regards,
Laurent