Topic: Unable to call script function from code with parameters
We've already discussed this before, but I thought I'd make a separate thread in a more logical place.
Basically, what's going on is that in order to give parameters to lua, we need to push values in. This is all fine. We can do this. But then we also need to give a number to lua_pcall to tell it how many arguments(so it knows how many to take off the stack). This is also not too much of a problem.
The problem is when we need to push the arguments after we give it a function to look up (so we say, "we have this function, here are the arguments, oh, and by the way, can you call it with 4 arguments?")
I've looked into popping the arguments off the stack, then calling lua_getglobal to find the function, then pushing them back on, but this isn't really realistic for a couple of reasons, firstly, we need to find some way to store them temporarily, and we also need to be able to store them in a general way (so not, for example, convert them into strings, as we lose context)
At this stage, I'm open to suggestions as to how I can patch this. The easiest way I can see is splitting the call into 2 functions (beginCallFunction(...) endCallFunction(...)) and then wrapping them in callFunction if there are no arguments. For arguments, they can be done in between begin and end. Alternatively, we could somehow build a stack ourselves, and pass the stack to callFunction. Finally, can continue down the popping/pushing route I started taking, but that looked pretty painful...