This is quite possibly the wrong title, but I don't know how else to describe it. What I'm trying to do is call a C++ function from my scripting language (running in a VM). I've run into some trouble figuring out how to pass in parameters to the function.
My best solution so far is to do this:
void func(int a) {
// Start param copy
char c;
char* par_start = &c - sizeof(char) - getCurrentFuncParamOffset();
copyCurrentParams(par_start);
// End copy
// Code
}
Then, to call the function I first expose it to the VM, giving the parameters to it. This is some shortened code, but everything is cast to a void(*) so it can be stored in a hash table.
EXPOSE(test, int);
vm.call("test", 12)
EXPOSE grabs a pointer to the function test, and stores that it requires a single into to be called. It stores the pointer as a void(*)() in a hash table so that when I want to call it, I can make a call from the VM and it is resolved. Then the code inside of the function (which I have expanded from a macro in the question) will copy the parameters that were passed in from the call to the VM to the parameters of the function.
This works but it is not the most elegant solution, especially because I'll have to call a macro for each function that I want to be exposed for scripting. Is there a better solution? Thanks.
EXPOSEmacro? What iscppFunction? What is the point ofvoid(*ptr)()=(void(*)());?