lua-users home
lua-l archive

Calling the same function over and over again from C

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


Hi all!
I was just wondering if there is a way to speed-up calling the same function over and over again from C++ to LUA.
My point is, let's say we want to call the function "PerFrame()" (just for sake of argument), it would be something like:
lua_pushstring(VM, "PerFrame");
lua_gettable(VM, LUA_GLOBALSINDEX);
lua_call(VM, 0, 0);
The first two lines are to seek a pointer to the actual function on the stack. It seems rather slow to have to convert the string to function every call. Is there a way to simply get whatever is on the stack (eg. a function) and push it onto the stack later on?
I'm thinking something like this:
Only one time we do:
lua_pushstring(VM, "PerFrame");
lua_gettable(VM, LUA_GLOBALSINDEX);
followed by something like:
PerFrameFunction = lua_getfromstack(VM, 1); // so I made up "lua_getfromstack" here...
...and per-frame we do something like:
lua_pushtostack(VM, PerFrameFunction);
lua_call(VM, 0, 0);
It would be nice to be able to do the same for a function in a table whilst reserving 'self'.
Did I miss how to do this or isn't it possible (yet? :) with LUA?
Thanks,
Hugo

AltStyle によって変換されたページ (->オリジナル) /