};
struct dlua_push_notification_txn_context {
- void *ptr;
+ int tx_ref;
};
#define DLUA_DEFAULT_EVENTS (\
/* store the result */
struct dlua_push_notification_txn_context *tctx =
p_new(dtxn->ptxn->pool, struct dlua_push_notification_txn_context, 1);
- /* this is just for storage */
- tctx->ptr = tctx;
- lua_pushlightuserdata(ctx->script->L, tctx->ptr);
- /* move light userdata before the return value from pcall */
- lua_insert(ctx->script->L, -2);
- /* push this into LUA_REGISTRYINDEX */
- lua_settable(ctx->script->L, LUA_REGISTRYINDEX);
+ tctx->tx_ref = luaL_ref(ctx->script->L, LUA_REGISTRYINDEX);
dtxn->context = tctx;
return TRUE;
static void
push_notification_driver_lua_call(struct dlua_push_notification_context *ctx,
- void *context, struct mail_user *user,
+ struct dlua_push_notification_txn_context *tctx,
+ struct mail_user *user,
const struct push_notification_txn_event *event,
const struct push_notification_txn_mbox *mbox,
struct push_notification_txn_msg *msg)
}
/* push context */
- lua_pushlightuserdata(ctx->script->L, context);
- lua_gettable(ctx->script->L, LUA_REGISTRYINDEX);
+ lua_rawgeti(ctx->script->L, LUA_REGISTRYINDEX, tctx->tx_ref);
/* push event + common fields */
if (mbox != NULL) {
if (array_is_created(&mbox->eventdata)) {
array_foreach(&mbox->eventdata, event) {
- push_notification_driver_lua_call(ctx, tctx->ptr, user,
+ push_notification_driver_lua_call(ctx, tctx, user,
(*event), mbox, NULL);
}
}
if (array_is_created(&msg->eventdata)) {
array_foreach(&msg->eventdata, event) {
- push_notification_driver_lua_call(ctx, tctx->ptr, user,
+ push_notification_driver_lua_call(ctx, tctx, user,
(*event), NULL, msg);
}
}
{
/* call end txn */
struct dlua_push_notification_context *ctx = dtxn->duser->context;
+ struct dlua_push_notification_txn_context *tctx = dtxn->context;
struct mail_user *user = dtxn->ptxn->muser;
lua_getglobal(ctx->script->L, DLUA_FN_END_TXN);
} else {
push_notification_driver_debug(DLUA_LOG_LABEL, user,
"Calling " DLUA_FN_END_TXN);
- lua_pushlightuserdata(ctx->script->L, dtxn->context);
- lua_gettable(ctx->script->L, LUA_REGISTRYINDEX);
+ lua_rawgeti(ctx->script->L, LUA_REGISTRYINDEX, tctx->tx_ref);
lua_pushboolean(ctx->script->L, success);
if (lua_pcall(ctx->script->L, 2, 0, 0) != 0) {
i_error("push_notification_lua: %s",
}
/* release context */
- lua_pushlightuserdata(ctx->script->L, dtxn->context);
- lua_pushnil(ctx->script->L);
- lua_settable(ctx->script->L, LUA_REGISTRYINDEX);
+ luaL_unref(ctx->script->L, LUA_REGISTRYINDEX, tctx->tx_ref);
mail_user_unref(&user);
}