static intp_result_t bool_to_int (bool b) { if (b) return make_int_result(1); else return make_int_result(0); }
static intp_result_t boolify_int (int64_t i) { if (i) return make_int_result(1); else return make_int_result(0); }
static int mosq_publish(lua_State *L) { mosq_t *ctx = mosq_get(L, 1); int mid; /* message id is referenced in the publish callback */ const char *topic = luaL_checkstring(L, 2); size_t payloadlen = 0; const void *payload = NULL; if (!lua_isnil(L, 3)) { payload = lua_tolstring(L, 3, &payloadlen); }; int qos = luaL_optinteger(L, 4, 0); bool retain = lua_toboolean(L, 5); int rc = mosquitto_publish(ctx->mosq, &mid, topic, payloadlen, payload, qos, retain); if (rc != MOSQ_ERR_SUCCESS) { return make_mosq_status_result(L, rc); } return make_int_result(L, true, mid); }
static int mosq_unsubscribe(lua_State *L) { mosq_t *ctx = mosq_get(L, 1); int mid; const char *sub = luaL_checkstring(L, 2); int rc = mosquitto_unsubscribe(ctx->mosq, &mid, sub); if (rc != MOSQ_ERR_SUCCESS) { return make_mosq_status_result(L, rc); } return make_int_result(L, true, mid); }