Skip to content

[cppia] Convert values when host code calls script implementations of host interfaces - #1460

Open
Simn wants to merge 1 commit into
masterfrom
cppia-host-generic-interface
Open

Simn wants to merge 1 commit into
masterfrom
cppia-host-generic-interface

Conversation

@Simn

@Simn Simn commented Nov 2, 2026

Copy link
Copy Markdown
Member

Host code calls interface functions with the native signature, which uses Dynamic for type parameters. A script class implementing a host interface with more specific types, e.g. IMap<String, String>, then reads the pushed values as the wrong types. This made get return garbage/null or crash, both for calls from host code and for script calls (which go through the host's interface functions). This was found via HaxeFoundation/haxe#13118, where a test implementing IMap fails on cppia.

When linking a script class's interface vtable slots, functions whose argument or return types differ from the native signature are now wrapped in an adapter. It reads the arguments using the native types, converts them via pushArgsDynamic, calls the script function and converts the return value back. The adapter itself has the native signature, so script calls through the same slot still push matching values. Functions whose signature already matches are used directly as before.

Adds NativeInterfaceTypes to the cppia client tests, with script implementations of IMap<String, String> and IMap<Int, Float>. Both tests fail without the fix, and pass with it, interpreted and with -jit.

Unrelated, noticed while looking at this: CppiaModule::getInterfaceSlot returns interfaceSlots.size()+1 for new names, but the host's names start at slot 2, so the first new script-only interface function name gets the same slot as the last host one.

🤖 Generated with Claude Code

… host interfaces

Host code calls interface functions with the native signature, which uses
Dynamic for type parameters. Script implementations with more specific types,
such as a class implementing IMap<String, String>, read those values as the
wrong types. Wrap such functions in an adapter that converts the arguments
and the return value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Simn

Simn commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

Uh, that doesn't look great...

@tobil4sk

tobil4sk commented Nov 2, 2026

Copy link
Copy Markdown
Member

Is this not more of a cppia generator issue? How do other targets handle this

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