Im making a haxe community account because im genuinely about to lose my mind with this
if i try and pass a haxe type into a native c++ function
function foo(bar:Dynamic) // does cool native stuff
and then i try and call the function like this
foo(Int) // or another type
when the c++ code is generated it becomes ::hx::ClassOf<T>() (so ::hx::ClassOf<int>(), in this instance)
I want it to just be T (or just int) in this context
You are unable to. That ::hx::ClassOf() is purposeful in haxe-cpp.
Hxcpp must produce a runtime object since foo(Int) passes a Haxe class value rather than a C++ type. At that point, Int ≠ int, and Haxe cannot be forced to provide “just T” or “just int.”
Your actual choices if you require compile-time C++ types are:
Using macros to create customized calls
native overloads that are explicit
pass a tag or enum in place of a type
Because of the way the backend operates, hxcpp is unable to drive C++ templates via Class.
var r:Dynamic = null;
switch (type) {
case Int:
r = untyped __cpp__("{0}.cast<int>()", this);
case Int64:
r = untyped __cpp__("{0}.cast<::cpp::Int64>()", this);
case UInt64:
r = untyped __cpp__("{0}.cast<uint64_t>()", this);
case Float:
r = untyped __cpp__("{0}.cast<::Float>()", this);
case Float32:
r = untyped __cpp__("{0}.cast<::cpp::Float32>()", this);
case Float64:
r = untyped __cpp__("{0}.cast<::cpp::Float64>()", this);
case Bool:
r = untyped __cpp__("{0}.cast<bool>()", this);
case String:
r = untyped __cpp__("{0}.cast<::String>()", this);
case null:
r = untyped __cpp__("{0}.cast<null>()", this);
default:
r = untyped __cpp__("{0}.cast<::Dynamic>()", this);
}
return cast r;