lua-users home
lua-l archive

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


2011/7/16 Gaspard Bucher <gaspard@teti.ch>:
> I am considering using ffi for OpenGL, but I do not like the "gl" scoping
> redundancy:
> gl.glMatrixMode(gl.GL_PROJECTION)
> Is it possible to somehow alias the constants and method calls in order to
> have ?
> gl.MatrixMode(gl.PROJECTION)

That's funny, I have exactly the same problem with the GSL library,
I've a lot of code like that:

cgsl.gsl_matrix_set (m, i, j, x)

I guess it is a common problem since C libraries needs to create the
illusion of a namespace using a common prefix for all the functions.

I'm wondering if we can have a simple and efficient solution for this
cosmetic problem. A solution could be the following:

local cgl = gl

local mt = {
  __index = function(t, k) return cgl["gl" .. k] end
}

gl = setmetatable({}, mt)

Of course the concern here is that the code above could potentially
slow the function lookup. For the other side I'm wondering if Mike is
going to hack LuaJIT to address this problem... may be yes, who know ?
:-)

Anyway, I would be not surprised if Mike devise a smart solution that
we would have never thought :-)
-- 
Francesco