Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compat.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#if LUA_VERSION_NUM < 502
# include <assert.h>
# define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
# define luaL_setfuncs(L,l,n) (assert(n==0), luaL_register(L,NULL,l))
#endif
Expand Down
21 changes: 8 additions & 13 deletions lua-mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@
* @module mosquitto
*/

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <assert.h>

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

#include <mosquitto.h>
Expand Down Expand Up @@ -85,7 +82,7 @@ typedef struct {
static int mosq_initialized = 0;

/* handle mosquitto lib return codes */
static int mosq__pstatus(lua_State *L, int mosq_errno) {
static inline int mosq__pstatus(lua_State *L, int mosq_errno) {
switch (mosq_errno) {
case MOSQ_ERR_SUCCESS:
lua_pushboolean(L, true);
Expand Down Expand Up @@ -133,11 +130,9 @@ static int mosq__pstatus(lua_State *L, int mosq_errno) {
static int mosq_version(lua_State *L)
{
int major, minor, rev;
char version[16];

mosquitto_lib_version(&major, &minor, &rev);
sprintf(version, "%i.%i.%i", major, minor, rev);
lua_pushstring(L, version);
lua_pushfstring(L, "%d.%d.%d", major, minor, rev);
return 1;
}

Expand Down Expand Up @@ -204,7 +199,7 @@ static int mosq_cleanup(lua_State *L)
return mosq__pstatus(L, MOSQ_ERR_SUCCESS);
}

static void ctx__on_init(ctx_t *ctx)
static inline void ctx__on_init(ctx_t *ctx)
{
ctx->on_connect = LUA_REFNIL;
ctx->on_disconnect = LUA_REFNIL;
Expand All @@ -215,7 +210,7 @@ static void ctx__on_init(ctx_t *ctx)
ctx->on_log = LUA_REFNIL;
}

static void ctx__on_clear(ctx_t *ctx)
static inline void ctx__on_clear(ctx_t *ctx)
{
luaL_unref(ctx->L, LUA_REGISTRYINDEX, ctx->on_connect);
luaL_unref(ctx->L, LUA_REGISTRYINDEX, ctx->on_disconnect);
Expand Down Expand Up @@ -262,7 +257,7 @@ static int mosq_new(lua_State *L)
return 1;
}

static ctx_t * ctx_check(lua_State *L, int i)
static inline ctx_t * ctx_check(lua_State *L, int i)
{
return (ctx_t *) luaL_checkudata(L, i, MOSQ_META_CTX);
}
Expand Down Expand Up @@ -539,7 +534,7 @@ static int ctx_threaded_set(lua_State *L)
static int ctx_option(lua_State *L)
{
ctx_t *ctx = ctx_check(L, 1);
enum mosq_opt_t option = luaL_checkint(L, 2);
enum mosq_opt_t option = luaL_checkinteger(L, 2);
int type = lua_type(L, 3);
int rc;

Expand Down Expand Up @@ -750,7 +745,7 @@ static int ctx_unsubscribe(lua_State *L)
}
}

static int mosq_loop(lua_State *L, bool forever)
static inline int mosq_loop(lua_State *L, bool forever)
{
ctx_t *ctx = ctx_check(L, 1);
int timeout = luaL_optinteger(L, 2, -1);
Expand Down Expand Up @@ -1253,7 +1248,7 @@ static int callback_type_from_string(const char *typestr)
return -1;
}

static void mosq_register_defs(lua_State *L, const struct define *D)
static inline void mosq_register_defs(lua_State *L, const struct define *D)
{
while (D->name != NULL) {
lua_pushinteger(L, D->value);
Expand Down