diff --git a/src/LuaEngine.h b/src/LuaEngine.h index 98292fb..ff3178d 100644 --- a/src/LuaEngine.h +++ b/src/LuaEngine.h @@ -9,6 +9,7 @@ #include "croncpp/croncpp.h" #include #include +#include "spdlog/spdlog.h" struct ScheduledService { cron::cronexpr cron; @@ -73,4 +74,16 @@ inline bool check_arguments(lua_State* lua, int stack_pos) { return lua_isnumber(lua, stack_pos); } +template +void lua_func_call(LuaService& service, const std::string& lua_func, F push_params) { + lua_getglobal(service.lua, lua_func.c_str()); + + int num_arguments = push_params(); + + if (lua_pcall(service.lua, num_arguments, 0, 0) != 0) { + spdlog::error("[{}] Unable to call '{}'. [Lua: '{}']", lua_func, service.name); + + return; + } +} #endif // LUA_ENGINE_H diff --git a/src/Version.h b/src/Version.h index 20eefe1..2c12f55 100644 --- a/src/Version.h +++ b/src/Version.h @@ -2,7 +2,7 @@ #define VERSION_H #define THRAWN_MAJOR_VERSION 1 -#define THRAWN_MINOR_VERSION 0 -#define THRAWN_PATCH_VERSION 5 +#define THRAWN_MINOR_VERSION 1 +#define THRAWN_PATCH_VERSION 0 #endif // VERSION_H diff --git a/src/thrawn_api.cpp b/src/thrawn_api.cpp index 371c0b1..e1e910b 100644 --- a/src/thrawn_api.cpp +++ b/src/thrawn_api.cpp @@ -254,13 +254,13 @@ int thrawn_publish(lua_State* lua) { } void call_thrawn_on_start(LuaService& service) { - thrawn_call(service, "thrawn_on_start", [&]() { + lua_func_call(service, "thrawn_on_start", [&]() { return 0; }); } void call_thrawn_on_update(LuaService& service, TopicState state) { - thrawn_call(service, "thrawn_on_update", [&]() { + lua_func_call(service, "thrawn_on_update", [&]() { push_topic_state_table(service.lua, state); return 1; @@ -268,7 +268,7 @@ void call_thrawn_on_update(LuaService& service, TopicState state) { } void call_thrawn_on_schedule(LuaService& service, std::time_t now, const std::string& callback) { - thrawn_call(service, callback.c_str(), [&]() { + lua_func_call(service, callback.c_str(), [&]() { lua_pushinteger(service.lua, now); return 1; diff --git a/src/thrawn_api.h b/src/thrawn_api.h index 0857f0f..9507138 100644 --- a/src/thrawn_api.h +++ b/src/thrawn_api.h @@ -1,6 +1,5 @@ #if !defined(THRAWN_API_H) #define THRAWN_API_H -#include extern "C" { @@ -47,17 +46,4 @@ int thrawn_log_light(lua_State* lua); int thrawn_log_light_dimmable(lua_State* lua); int thrawn_log_light_tw(lua_State* lua); - -template -void thrawn_call(LuaService& service, const std::string& lua_func, F push_params) { - lua_getglobal(service.lua, lua_func.c_str()); - - int num_arguments = push_params(); - - if (lua_pcall(service.lua, num_arguments, 0, 0) != 0) { - spdlog::error("[{}] Unable to call '{}'. [Lua: '{}']", lua_func, service.name); - - return; - } -} #endif // THRAWN_API_H \ No newline at end of file