Hey guys,
how would you import from cpp a type with this form:
template <typename... Types>
struct TTuple : UE4Tuple_Private::TTupleBase<TMakeIntegerSequence<uint32, sizeof...(Types)>, Types...>
and a method with:
template <typename... Types>
FORCEINLINE TTuple<typename TDecay<Types>::Type...> MakeTuple(Types&&... Args)
it allows for:
TTuple<std:string, int> tuple = MakeTuple("string", 2)
or TTuple<Pointer*> tuple2 = MakeTuple(new Pointer())
or in general n number of types with n number of arguments
Thanks,
Juan
The nearest thing i could achieve is this:
import macros
{.emit: """/*TYPESECTION*/
#include <tuple>
#include <utility>
template <typename... Types>
struct TTuple : std::tuple<Types...>
{
};
""".}
type
TTuple1[T] {.importcpp:"TTuple<'*0>".} = object
TTuple2[T1, T2] {.importcpp:"TTuple<'*0, '*1>".} = object
macro TTuple(types: varargs[untyped]): untyped =
result = nnkBracketExpr.newTree newIdentNode("TTuple" & $len(types))
for t in types:
result.add newIdentNode($t)
var x1 : TTuple(int)
discard x1
var x2 : TTuple(int, float)
discard x2
But accessing by index needs some work, tried adding these:
proc `[]=`[T](this: var TTuple1[T], idx: int, value: T) {.importcpp:"std::get<#>(#) = #;".}
proc `[]`[T](this: var TTuple1[T], idx: int): T {.importcpp:"std::get<#>(#)".}
but unfortunately there is no way to substitute arguments to importcpp by positional index when using #
Sure, but it's totally unrelated. A bit of context, Im doing a POC of a plugin to use Nim in Unreal Engine using Unreal's reflection system as a binding mechanism (in contrast as the prev one that relied on generating cpp, this one it's a dyn lib which has a few adv).
I did a wrapper on cpp that allows you to call any arbitrary function, before it used that TTuple type but then found out that nim's objects also does the job, didnt knew you can define them inside a proc, so now Im just passing over a pointer to the object and Im able to pick them up on the cpp side and call the function "dynamically"
I'm binding the juce framework, something i've been using and contributing in the last 2 decades or so.
I've already created its python bindings i'm using for quick app prototyping > https://github.com/kunitoki/popsicle