Refactor: Split out some code from output_flex_t class #2324
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.
The class output_flex_t is huge, output-flex.cpp with over 1000 lines is the largest source code file we have. This change moves some code out of there.
This change introduces a new templated wrapper base class (lua_wrapper_base) for wrapping C++ objects in Lua. It is then used for the "Table" and "ExpireOutput" Lua objects. Functions that are called from Lua on those objects are called through the wrapper on the underlying C++ objects using little wrapper functions in the wrapper classes. A new macro TRAMPOLINE_WRAPPED_OBJECT() is used to call these functions where we used the TRAMPOLINE() macro before.
One problem is though that more complex functions need more of the machinery in the output_flex_t class to work, specifically this is the "insert" function for tables which can not be implemented without full access to the output_flex_t class. So this function keeps using the old mechanism.
This also changes the get_from_idx_param() helper function and the functions using it
(output_flex_t::[get_table|expire_output]_from_param()) to return a reference instead of a const reference so that the wrapper will be initialized with a mutable pointer to the underlying C++ class. Currently all functions that can be called through the wrapper are const functions, but this will not necessarily always be the case in the future.