-
-
Notifications
You must be signed in to change notification settings - Fork 669
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
feat: implementation of lua/c++ event callback system #1317
Merged
dudantas
merged 20 commits into
opentibiabr:main
from
dudantas:feat-lua-event-callback-system
Aug 1, 2023
Merged
feat: implementation of lua/c++ event callback system #1317
dudantas
merged 20 commits into
opentibiabr:main
from
dudantas:feat-lua-event-callback-system
Aug 1, 2023
+3,156
−442
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We've implemented a callback system that allows interaction between C++ code and Lua scripts. Functions defined in C++ can be sent to a Lua script, which can manipulate them and return them to the C++ code. This allows for greater flexibility and interactivity between the two code layers, allowing functions to be manipulated at runtime by the Lua script. Key changes include: • Addition of the EventCallback class encapsulating callback functionality. • Implementation of callback functions in the CallbackFunctionsBinder class. • Registration of callback functions to the Lua interface. These changes should be carefully reviewed to ensure the interaction between C++ and Lua is functioning as expected and that there are no memory leaks or other potential issues.
13 tasks
moviebr
reviewed
Jul 28, 2023
98259a2
to
313cf7b
Compare
luan
approved these changes
Jul 28, 2023
moviebr
approved these changes
Jul 28, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Muito bom!
This commit introduces a significant refactor in the way callbacks are executed. It unifies the two existing callback execution functions into a single templated function that uses perfect forwarding. The new `executeCallback` function accepts any number of arguments of any type, and can handle both `void` and `bool` return types. It uses the C++ perfect forwarding mechanism to preserve the lvalue-ness or rvalue-ness of its arguments when they're passed to the callback function. This change simplifies the code and reduces redundancy, while preserving the flexibility and robustness of the callback execution mechanism. It also ensures that all callbacks are executed even if some of them return `false`. Furthermore, this commit improves the readability and maintainability of the code by removing the need for long chains of `if-else` statements in the callback registration function. Instead, a lookup table is used to map callback types to their respective functions.
…udantas/canary into feat-lua-event-callback-system
bce660f
to
86fadb3
Compare
c5af56c
to
23adfa9
Compare
23adfa9
to
947cfdb
Compare
SonarCloud Quality Gate failed.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
We've implemented a callback system that allows interaction between C++ code and Lua scripts. Functions defined in C++ can be sent to a Lua script, which can manipulate them and return them to the C++ code. This allows for greater flexibility and interactivity between the two code layers, allowing functions to be manipulated at runtime by the Lua script.
Key changes include:
• Addition of the EventCallback class encapsulating callback functionality.
• Implementation of callback functions in the CallbackFunctionsBinder class.
• Registration of callback functions to the Lua interface.
These changes should be carefully reviewed to ensure the interaction between C++ and Lua is functioning as expected and that there are no memory leaks or other potential issues.
Fixes #1228
Type of change
Checklist