bottlenoselabs / c2cs

Generate C# bindings from a C header.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Function pointers: implicit cast

lithiumtoast opened this issue · comments

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)
{
    ...
}

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.

Closing for now.