lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Mon, Aug 29, 2016 at 10:18 PM, Omega Extern <> wrote:

1. Store a reference to the original/native C (in this case `player.GetInfo') function (I guess I would have to execute that first, before replacement)?

2. Get the number of arguments the user have supplied upon the call of new/replaced `player.GetInfo' function?

3. Call the original function with variable number of arguments (varargs) that are being passed to the new/replaced `player.GetInfo' function?

Observe the arguments are already on stack. So you could try to re-use them. To call the original function, you have to push it on stack, but then the order of things on stack will be wrong; the function to be called must be pushed before, not after, its arguments. So you need to rotate the stack. See if you can find a way to do that.

4. Finally, get the number of results after the original function is called (in the new/replaced `player.GetInfo' function)?

You have already found LUA_MULTIRET. Observe that after the original function has returned, its return values are already on stack. Then read again: how could you just say to Lua "treat them as if I returned them"?