0

I'm trying to add internal calls to mono like follows:

void addCall(char *name, char *amx_name)
{
    AMX_NATIVE native = sampgdk::FindNative(name);

    void(*natcall)() = []()
    {
        //Can't access native here... :(
        callNative(native);
    };
    mono_add_internal_call(name, (void *)natcall);
}

The internal call should call a method with some data(the pointer to the native, AMX_NATIVE). However, the value can't be accessed within the lambda code.

When you use variable capture ( [&]() { ... } ) the lambda code can't be cast to a void * which i need to call mono_add_internal_call.

Can someone think of a way around this issue?

ikkentim
  • 1,639
  • 15
  • 30

1 Answers1

-1

Why don't you just have FindNative return the function pointer and pass it to mono_add_internal_call? Why do you need a callNative function? I can't say without knowing about that 3rd party library.

Think of it like this: function pointers are addresses to COMPILED code. A lamda with capture is not static. Such a function pointer would need to know where to find the "native" variable it is expecting.

Do you know all of the functions you need to add, ahead of time? If so, why not allow your internal call to have an argument to an enum with the index of the native method? It's not much better than exporting them all by hand though.

James
  • 1
  • For FindNative is a function from an external library. The purpose of addCall is to dynamically add internal calls to "native" functions provided by the sampgdk library. Since I've asked this question I've worked around this issue by handling the passing of the name of the "native" function in C#. I've added one internal call which looks something like ```call_native_array(MonoString *name_string, MonoString *format_string, MonoArray *args_array)``` which handles all calls to "native" functions. – ikkentim Feb 08 '15 at 17:29