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

feat: implementation of lua/c++ event callback system #1317

Merged
merged 20 commits into from
Aug 1, 2023

Conversation

dudantas
Copy link
Member

@dudantas dudantas commented Jul 28, 2023

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

  • New feature (non-breaking change which adds functionality)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I checked the PR checks reports
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

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.
@dudantas dudantas force-pushed the feat-lua-event-callback-system branch from 98259a2 to 313cf7b Compare July 28, 2023 20:14
Copy link

@moviebr moviebr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Muito bom!

dudantas and others added 9 commits July 29, 2023 00:43
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.
@dudantas dudantas force-pushed the feat-lua-event-callback-system branch from bce660f to 86fadb3 Compare July 29, 2023 06:26
@dudantas dudantas force-pushed the feat-lua-event-callback-system branch from c5af56c to 23adfa9 Compare July 29, 2023 17:17
@dudantas dudantas force-pushed the feat-lua-event-callback-system branch from 23adfa9 to 947cfdb Compare July 29, 2023 17:19
@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 1, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 107 Code Smells

0.0% 0.0% Coverage
15.5% 15.5% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@dudantas dudantas merged commit f518fdf into opentibiabr:main Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EventCallback
4 participants