From e5c5b638921134824001fd72d686d20fb5df9ce7 Mon Sep 17 00:00:00 2001 From: Tamino Bauknecht Date: Thu, 28 Mar 2024 21:41:15 +0100 Subject: [PATCH 1/2] lua_state: Add integer overloads for pushOne Otherwise, a small type mismatch (e.g. long long instead of int) will cause ambiguity with e.g. the double overload. --- include/lua/lua_state.h | 11 +++++++++-- src/lua_state.cpp | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/lua/lua_state.h b/include/lua/lua_state.h index 3bc80f1..0ffee8c 100644 --- a/include/lua/lua_state.h +++ b/include/lua/lua_state.h @@ -134,7 +134,15 @@ class LuaState { std::optional> popFunction(bool always_pop = false); void pushOne(double value); - void pushOne(int value); + // NOLINTBEGIN(google-runtime-int) + // TODO: use template instead + void pushOne(unsigned int value) { pushOne(static_cast(value)); } + void pushOne(int value) { pushOne(static_cast(value)); } + void pushOne(unsigned long value) { pushOne(static_cast(value)); } + void pushOne(long value) { pushOne(static_cast(value)); } + void pushOne(unsigned long long value) { pushOne(static_cast(value)); } + void pushOne(long long value); + // NOLINTEND(google-runtime-int) void pushOne(const char* value); void pushOne(std::string_view value); void pushOne(bool value); @@ -259,7 +267,6 @@ auto LuaState::topFunction() } return std::optional { std::nullopt }; } - } // namespace ppplugin #endif // PPPLUGIN_LUA_STATE_H diff --git a/src/lua_state.cpp b/src/lua_state.cpp index 6c75962..911c342 100644 --- a/src/lua_state.cpp +++ b/src/lua_state.cpp @@ -77,7 +77,8 @@ void LuaState::pushOne(double value) lua_pushnumber(state(), value); } -void LuaState::pushOne(int value) +// NOLINTNEXTLINE(google-runtime-int) +void LuaState::pushOne(long long value) { lua_pushinteger(state(), value); } From 84560d45636e2d3bf8a9b631cb16daaa6732f3e4 Mon Sep 17 00:00:00 2001 From: Tamino Bauknecht Date: Thu, 28 Mar 2024 21:24:56 +0100 Subject: [PATCH 2/2] examples: Install two lua example plugins --- examples/lua_plugin/CMakeLists.txt | 4 +++- examples/lua_plugin/lua_plugin_manager.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/lua_plugin/CMakeLists.txt b/examples/lua_plugin/CMakeLists.txt index 4d6708b..09c45f4 100644 --- a/examples/lua_plugin/CMakeLists.txt +++ b/examples/lua_plugin/CMakeLists.txt @@ -5,4 +5,6 @@ add_custom_command( TARGET lua_plugin_manager POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/plugin.lua - $) + $/plugin_1.lua + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/plugin.lua + $/plugin_2.lua) diff --git a/examples/lua_plugin/lua_plugin_manager.cpp b/examples/lua_plugin/lua_plugin_manager.cpp index 8cc8f9d..88a95b0 100644 --- a/examples/lua_plugin/lua_plugin_manager.cpp +++ b/examples/lua_plugin/lua_plugin_manager.cpp @@ -36,9 +36,11 @@ int main(int argc, char* argv[]) // only load files ending with ".lua" and execute in separate thread if (path.extension() == ".lua") { if (auto plugin = manager.loadLuaPlugin(path)) { - threads.emplace_back([plugin = std::move(*plugin)]() mutable { + threads.emplace_back([plugin = std::move(*plugin), plugin_number = threads.size()]() mutable { + // data race due to shared resource "stdout", + // but Lua plugins are otherwise thread-safe std::ignore = plugin.call("initialize"); - std::ignore = plugin.call("loop", "2"); + std::ignore = plugin.call("loop", plugin_number); }); } }