Repository navigation
Description
As part of the typed callables work I had to disable cppia mem references in two places to get all the tests passing, this was due to an unfortunate edge case involving haxe functions.
E.g. Haxe is perfectly happy to treat the following signatures as compatible without any user casting or manual wrapping.
Int->Void = Dynamic->Void
Float->Void = Int->Void
Without cppia this is all fine as the new callable types constructor deals with all this mangling, but with cppia there are a few annoying edge cases. Cppia erases all objects to hx::Object*, so when you pass an object like hx::ObjectPtr<hx::Callable<Int->Void>> from haxe into cppia it gets erased to just a object pointer. But this also means if you pass in a Haxe compatible hx::ObjectPtr<hx::Callable<Dynamic->Void>> it will also be erased to hx::Object* and the mem reference setter will just replace the pointer. The problems then start to occur when we try and pull that function object out of cppia and back into cpp. The pointer will be blindly reinterpreted to the original hx::ObjectPtr<hx::Callable<Int->Void>> (or whatever haxe deems the expression to be) which will cause a memory access violation if that pointer holds the one where Dynamic is the argument as they're incompatible types. Previously this would "just work" as all function closures invoked dynamically.
The other edge case surrounding passing these odd compatible callables over the cppia boundary is that you can end up with a callable object pointer in cpp holding a pointer to a hx::CppiaClosure which does not inherit a callable type, again this is due to pointers being reinterpreted by mem reference instead of going through the required callable constructor.
I still have a screenshot of this second one since it was fixed in a follow up merge.
Hopefully this makes sense, I'm not massively familiar with cppia so I found the easiest fix was to disable mem references for objects which is obviously not great. I'll try and remember to dig out some concrete examples of both of these.
Pinging @hughsando since he asked about it in a commit message.
Activity
hughsando commentedon Aug 6, 2026
If the direct setting were disabled only for the callable objects, that would probably resolve most of the potential performance issues.
I'm not familiar with the new callable code. I assume it works when set by name, which means the cppia "Dynamic" ends up in some kind of
operator=which wraps the Dynamic? So we could expose this with some kind of registry so that cppia can apply a transform before setting an object by memory. There is some stuff in there for Arrays - if cppia sets a hostArray<Int>from a Dynamic, it must potentially hard transform the object into andArray<Int>(eg, when reading from Json). This could probably be generalized a bit better than it is currently.I think the most "cppia native" way would be to have "scriptable" versions of each of the unique function typed used by the host stored in a registry. These would then push strongly typed values to the cppia stack (avoiding Dynamic anywhere, so benefit cppia too) and jump to the function code. Going the other way (cppia calling strongly typed closures) could stay dynamic, but could also be improved at some point.
Aidan63 commentedon Aug 9, 2026
Thanks, I hadn't thought of the array stuff, that does sound like it's having to solve the same problem. I'll take a look at it and see if I can adapt it for functions, hopefully shouldn't be too much effort and I can then take a look at that better typed closure stuff later on.
tobil4sk commentedon Nov 1, 2026
Just to keep a record, because the data will be deleted eventually: #1324 caused a regression observable in many of the benchmarks, e.g.
See also: #1324 (comment)
Link a cppia script's host static object fields directly below API 500
Fix seven runtime problems found in stock hxcpp's recent reports (#499)