Unified lua function calls by template
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#if !defined(THRAWN_API_H)
|
||||
#define THRAWN_API_H
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@@ -47,4 +48,16 @@ int thrawn_log_light_dimmable(lua_State* lua);
|
||||
|
||||
int thrawn_log_light_tw(lua_State* lua);
|
||||
|
||||
template<typename F>
|
||||
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
|
||||
Reference in New Issue
Block a user