Skip to content

Commit

Permalink
Proper lua module log message
Browse files Browse the repository at this point in the history
  • Loading branch information
CurlyMoo committed Jan 6, 2018
1 parent 84355dd commit f5de832
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions libs/pilight/lua/lua.c
Expand Up @@ -243,6 +243,19 @@ static int plua_module_init(struct lua_State *L, char *file, struct plua_module_
return 0;
}

char *type = NULL;
switch(mod->type) {
case FUNCTION: {
type = STRDUP("event function");
} break;
case OPERATOR: {
type = STRDUP("event operator");
} break;
}
if(type == NULL) {
OUT_OF_MEMORY
}

/*
* Returned table (first argument) is at top of stack
*
Expand All @@ -258,32 +271,38 @@ static int plua_module_init(struct lua_State *L, char *file, struct plua_module_

if(lua_istable(L, -1) == 0) {
logprintf(LOG_ERR, "%s: the info function returned %s, table expected", file, lua_typename(L, lua_type(L, -1)));
FREE(type);
return 0;
}

char *keys[12] = {"name", "version", "reqversion", "reqcommit"};
if(plua_table_has_keys(L, keys, 4) == 0) {
logprintf(LOG_ERR, "%s: the info table has invalid keys", file);
FREE(type);
return 0;
}

const char *name = NULL, *version = NULL, *reqversion = NULL, *reqcommit = NULL;
if(plua_get_table_string_by_key(L, "name", &name) == 0) {
logprintf(LOG_ERR, "%s: the info table 'name' key is missing or invalid", file);
FREE(type);
return 0;
}

if(plua_get_table_string_by_key(L, "version", &version) == 0) {
logprintf(LOG_ERR, "%s: the info table 'version' key is missing or invalid", file);
FREE(type);
return 0;
}

if(plua_get_table_string_by_key(L, "reqversion", &reqversion) == 0) {
logprintf(LOG_ERR, "%s: the info table 'reqversion' key is missing or invalid", file);
FREE(type);
return 0;
}
if(plua_get_table_string_by_key(L, "reqcommit", &reqcommit) == 0) {
logprintf(LOG_ERR, "%s: the info table 'reqcommit' key is missing or invalid", file);
FREE(type);
return 0;
}

Expand All @@ -309,19 +328,20 @@ static int plua_module_init(struct lua_State *L, char *file, struct plua_module_
}
}
if(valid == 1) {
logprintf(LOG_DEBUG, "loaded event action %s v%s", file, version);
logprintf(LOG_DEBUG, "loaded %s %s v%s", type, file, version);
} else {
if(strlen(mod->reqcommit) > 0) {
logprintf(LOG_ERR, "event action %s requires at least pilight v%s (commit %s)", file, mod->reqversion, mod->reqcommit);
logprintf(LOG_ERR, "%s %s requires at least pilight v%s (commit %s)", type, file, mod->reqversion, mod->reqcommit);
} else {
logprintf(LOG_ERR, "event action %s requires at least pilight v%s", file, mod->reqversion);
logprintf(LOG_ERR, "%s %s requires at least pilight v%s", type, file, mod->reqversion);
}
/*
* Pop function from stack
*
* The stack now contains: nothing
*/
lua_pop(L, 1);
FREE(type);
return 0;
}

Expand All @@ -331,6 +351,7 @@ static int plua_module_init(struct lua_State *L, char *file, struct plua_module_
* The stack now contains: nothing
*/
lua_pop(L, 1);
FREE(type);
return 1;
}

Expand Down

0 comments on commit f5de832

Please sign in to comment.