Skip to content

Refactor: Split out some code from output_flex_t class #2324

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

Merged
merged 1 commit into from
Apr 30, 2025

Conversation

joto
Copy link
Collaborator

@joto joto commented Apr 29, 2025

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.

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.
@lonvia lonvia merged commit 210fde0 into osm2pgsql-dev:master Apr 30, 2025
45 of 46 checks passed
@joto joto deleted the refactor-lua-wrapper branch April 30, 2025 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants