Pass BM function pointers to C/C++ code

BlitzMax Forums/BlitzMax Programming/Pass BM function pointers to C/C++ code

Hats off to Mark. Here is the answer. I'll tell everyone something right now... BM is awesome and an extermely powerful GameDev solution. Okay here it is:

C Code
------

int (*callback)(const char *);

void RegisterCallback ( int (*infunc)(const char *) )
{
callback = infunc;
}

void CallMe ()
{
callback("Hello from C");
}

BM Code
-------

Strict

Import "test.c"

Extern
Function RegisterCallback ( functionptr@Ptr )
Function CallMe ()
End Extern

Function Test:Int( char:Byte Ptr )
' OMG I just got a call back
DebugStop
End Function

RegisterCallback( Test )
CallMe()


----- END ------

So what is this good for? Well I'll be writing a small LUA module for BM. You'll be able to export your internal BM functions to LUA and have those callable from script. Makes scripting of bots, AI, missions, save games etc extermely easily. Well done Mark!