Repository navigation
Support loading compiled LUA modules - #262
Merged
Merged
Conversation
register_type<T, Flags> lets a caller opt a usertype out of sol2's automagic enrollments (comparison operators, index metamethods, ...), which matters for types wrapped via unique_usertype_traits where the underlying type doesn't support those operators. modify_type extends an already-registered usertype (e.g. one a plugin registered before) without re-running sol2's automagic registration, for the same reason. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TS5yFa1xBMh7dhCLj5yNi3
Towards a future plugin contract (C++ plugins registering directly, pure-Lua
script plugins, and compiled Lua plugins like adtl.so) that all report a
name+version and register under a namespace table keyed by that name, this
lands the prerequisite and the first (compiled-plugin) backend:
- create_decorated_environment's __index only ever decorated one level below
original_env: a type registered flat got tracked, but the same type nested
one level deeper (e.g. inside a namespace/plugin table) silently fell back
to raw, untracked calls - confirmed by a standalone repro against sol2
before touching anything. Replaced the hand-duplicated one-level logic
with decorate_value/decorate_table, a small mutually-recursive pair that
applies the same rule at any depth. Top-level caching and the globals
fallback are preserved exactly; a new test (module.nested_type_keeps_
dependency_tracking) locks in the previously-broken case, and all prior
tests still pass unchanged.
- state::load_module wraps luaL_requiref to load a compiled Lua C extension
(e.g. a SWIG-generated module) into the state's Lua interpreter.
- state::decorate_module_functions (made public - it already existed for
run_module_script) turns any plain Lua function found in a table into a
grunk-tracked function_meta, covering a module's free functions with one
call.
- external_type_proxy + state::register_external_type bridge a class whose
constructor/methods live behind foreign metatables (as SWIG-Lua's binding
does) by probing one instance and capturing each named method as an
unbound callable, generically, with no compile-time C++ type or hand-
written binding code involved. Operators need no separate bridging: once
a value is wrapped in a DynamicFeature, its existing generic operator
overloads already dispatch to the raw value's native metamethods with
full dependency tracking.
- PluginInfo{name, version} + state::load_compiled_plugin(info, open_fn)
wraps load_module+decorate_module_functions and registers the module's
table under original_env[name] (so its free functions are actually
reachable from a recipe, which nothing did before), recording the
plugin's identity in state::plugins().
- register_external_type's `name` is documented and handled as the type's
fully-qualified display path (e.g. "adtl.adouble"), not just its local
table key - needed once a type is nested, since ActionDynamic's
serialized form embeds that name verbatim and a saved recipe must still
resolve it correctly on read-back. A new test (dynamic_plugin.cpp)
exercises loading a fake compiled plugin, bridging a nested class, and
the construct + nested-method-call + serialize + deserialize round trip.
C++ and pure-Lua-script plugin backends are intentionally not implemented
yet, but PluginInfo/plugins() are shaped so a future state::begin_plugin
(handing back a namespace table for register_type/register_function or
run_module_script to populate directly) slots in without changing this.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TS5yFa1xBMh7dhCLj5yNi3
joergbrech
added a commit
that referenced
this pull request
Jul 24, 2026
register_external_type now auto-discovers member functions by probing an instance the first time each is looked up (merged in #262), so the explicit setADValue/getADValue/getValue listing is no longer needed to bridge adtl.adouble.
joergbrech
added a commit
that referenced
this pull request
Jul 27, 2026
joergbrech
added a commit
that referenced
this pull request
Sep 17, 2026
register_external_type now auto-discovers member functions by probing an instance the first time each is looked up (merged in #262), so the explicit setADValue/getADValue/getValue listing is no longer needed to bridge adtl.adouble.
This file contains hidden or 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
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.
Summary
Fixes #261.
Adds primitives to
grunk::statefor loading a compiled Lua plugin (e.g. a SWIG-generated module) and integrating it into grunk's dynamic type system, plus a core fix these primitives depend on. This is the first (compiled-Lua) backend of a planned plugin contract that will also cover pure-C++ and pure-Lua-script plugins (see #235) — those aren't implemented here.Also included: a small pre-existing, previously-unmerged
register_type/modify_typechange needed by geoml/OCCT-style types.Changes
Core fix: recursive decoration
create_decorated_environment's__indexonly ever decorated one level beloworiginal_env: a type registered flat (e.g.gp_Pnt) got dependency tracking, but the same type nested one level deeper (e.g. inside a namespace/plugin table) silently fell back to raw, untracked calls. Replaced the duplicated one-level logic withdecorate_value/decorate_table, a small mutually-recursivepair that applies the same decoration rule at any depth. Top-level caching and the globals fallback are preserved exactly as before.
Compiled-plugin loading
state::load_module(name, open_fn)— wrapsluaL_requirefto load a compiled Lua C extension into the state's interpreter.state::decorate_module_functions(now public — it already existed internally forrun_module_script) — turns any plain Lua function found in a table into a grunk-trackedfunction_meta.external_type_proxy+state::register_external_type— bridges a class whose constructor/methods live behind foreign metatables (as SWIG-Lua's binding does) by probing one instance and capturing each named method as an unbound callable, generically, with no compile-time C++ type or hand-written binding code required. Operators need no separate bridging: once a value is wrapped in aDynamicFeature, its existing generic operator overloads dispatch to the raw value's native metamethods with full dependency tracking.PluginInfo{name, version}+state::load_compiled_plugin(info, open_fn)— wrapsload_module+ decorate_module_functions, registers the module's table underoriginal_env[name](so its free functions are actually reachable from a recipe — nothing did this before), and records the plugin's identity viastate::plugins()`.register_external_type'snameis now documented/handled as the type's fully-qualified display path (e.g."occt.gp_Pnt"), not just its local table key — needed once a type is nested, since the serialized form of an action embeds that name verbatim and a saved recipe must still resolve it on read-back.register_type / modify_type (pre-existing, bundled in here)
register_type<T, Flags = sol::automagic_flags::all>lets a caller opt a usertype out of sol2's automagic enrollments (comparison operators, index metamethods, …) — needed for types wrapped viaunique_usertype_traitswhere the underlying type doesn't support those operators.modify_typeextends an already-registered usertype without re-running sol2's automagic registration, for the same reason.Not included
Pure-C++ and pure-Lua-script plugin backends.
PluginInfo/plugins()are shaped so a futurestate::begin_plugin(handing back a namespace table forregister_type/register_functionorrun_module_scriptto populate directly) can slot in without changing what's here.Tests
module.nested_type_keeps_dependency_tracking(new) — locks in the recursive-decoration fix.plugin.*(new,tests/cpp/dynamic_plugin.cpp) — loading a compiled plugin, tracking its free functions, and the full construct + nested-method + serialize + deserialize round trip for a bridged class.This PR is co-authored with Claude and thoroughly reviewed by me.