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...

Re: Unable to call script function from code with parameters

Hi, ok I understand now, arguments can only be pushed after 'lua_getglobal',
the begin/end two steps call makes sense, and callFunction won't need the numArgs parameter.

Feel free to commit that directly, thank you : )

Re: Unable to call script function from code with parameters

Right, I've just submitted this. It compiles and should work, but I haven't had a chance to test it. Basically, I've kept callFunction in there, but all it does is:

if(startCallFunction(name))
    endCallFunction();

with startCallFunction and endCallFunction doing the actual work. In theory, this should do it.

Re: Unable to call script function from code with parameters

cool, thanks : )