Skip to content

Commit

Permalink
examples: Install two lua example plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
taminob committed Mar 28, 2024
1 parent fc5e63b commit 3194881
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion examples/lua_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ add_custom_command(
TARGET lua_plugin_manager
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/plugin.lua
$<TARGET_FILE_DIR:lua_plugin_manager>)
$<TARGET_FILE_DIR:lua_plugin_manager>/plugin_1.lua
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/plugin.lua
$<TARGET_FILE_DIR:lua_plugin_manager>/plugin_2.lua)
6 changes: 4 additions & 2 deletions examples/lua_plugin/lua_plugin_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>("initialize");
std::ignore = plugin.call<void>("loop", "2");
std::ignore = plugin.call<void>("loop", plugin_number);
});
}
}
Expand Down

0 comments on commit 3194881

Please sign in to comment.