Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run lua_plugin example with two lua plugins #11

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 9 additions & 2 deletions include/lua/lua_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,15 @@ class LuaState {
std::optional<std::function<Func>> 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<long long>(value)); }
void pushOne(int value) { pushOne(static_cast<long long>(value)); }
void pushOne(unsigned long value) { pushOne(static_cast<long long>(value)); }
void pushOne(long value) { pushOne(static_cast<long long>(value)); }
void pushOne(unsigned long long value) { pushOne(static_cast<long long>(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);
Expand Down Expand Up @@ -259,7 +267,6 @@ auto LuaState::topFunction()
}
return std::optional<decltype(top_function)> { std::nullopt };
}

} // namespace ppplugin

#endif // PPPLUGIN_LUA_STATE_H
3 changes: 2 additions & 1 deletion src/lua_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading