Function pointers: implicit cast
lithiumtoast opened this issue · comments
Lucas Girouard-Stranks commented
Function proto mapping:
/** Action callback for systems and triggers */
typedef void (*ecs_iter_action_t)(
ecs_iter_t *it);
[StructLayout(LayoutKind.Explicit, Size = 8, Pack = 8)]
public struct ecs_iter_action_t
{
[FieldOffset(0)] // size = 8, padding = 0
public delegate* unmanaged<ecs_iter_t*, void> Pointer;
}
Right now, it is used like this:
var callback = default(ecs_iter_action_t);
callback.Pointer = &CallbackMethod;
...
[UnmanagedCallersOnly]
public static void CallbackMethod(ecs_iter_t* iterator)
{
...
}
It would be nice to be used like this:
var callback = default(ecs_iter_action_t);
callback = &CallbackMethod;
...
[UnmanagedCallersOnly]
public static void CallbackMethod(ecs_iter_t* iterator)
{
...
}
Lucas Girouard-Stranks commented
Turns out this is not possible currently due to C# special type syntax for function pointers. Can possible look into this again in the future.
Lucas Girouard-Stranks commented
Closing for now.