lua-users home
lua-l archive

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


On 2/17/2010 1:56 PM, Wesley Smith wrote:
If you wouldn't mind, I'd like to see a sample.  Your approach may work
better for me than some of the other proposals here because I'm using Lunar
to do my binding, and I do not have direct access to the object without
modifying Lunar, which I'd prefer not to do.

I did something similar to emulate OpenGL calls with Cairo graphics.
Cairo requires an object to draw with whereas in OpenGL the state
machine lives outside of the library.  If you look at line 260 of this
file, you'll see the for loop that transforms instance methods to
static methods:

http://www.mat.ucsb.edu/projects/luaAV/browser/branches/luaav3/extra/modules/cgl/init.lua

wes
Thanks for posting that, wes. Analyzing what you were doing helped my understand another poster's comments about shared functions and the overhead incurred by using this approach. In some situations it is probably not a big deal. In Bitfighter, some objects have 50 or so methods (and counting), and, in many cases, may be created and deleted within a single frame, so I could easily see having to create 500 or more "customized" methods 50 times per second, which might start incurring some overhead.

In a situation like the one I imagine you have, there is a single object that needs to be "wrapped", with a limited number of methods. Therefore, for you, the overhead is essentially 0.

Chris