lua-users home
lua-l archive

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


Hi,

I am trying to do some OpenGL via LuaJIT FFI. I've made 'gl' module that does cdef from gl.h file and and returns ffi.load('GL'). One can use it via `local gl = require('gl')`. Everything works great so far (using GLUT as well).

Now I want to provide some convenience functions for OpenGL functions expecting non-simple pointer types, such as glMaterialfv, so instead calling:

  gl.glMaterialfv(g.GL_FRONT, g.GL_SPECULAR,  ffi.new('GLfloat[4]', 1, 1, 1, 1));

One can call without using ffi (hiding ffi internals):
  gl.glMaterial(g.GL_FRONT, g.GL_SPECULAR, 1, 1, 1, 1)

When I try to make my wrapped using:
  gl.glMaterial = function(where, type, …)

I get missing declaration for symbol 'glMaterial' in function '__newindex'. This is expected as 'gl' isn't a table. But then alternatively to have single namespace I could just remap all functions into new table:
  M.function = glffi.glFunction

Such table could be extended with new entries for convenience functions and will make code look clear & pretty and be extensible, but will kill probably lookup overhead elimination as well (not recommended in http://luajit.org/ext_ffi_tutorial.html#cache).

So what would be the best solution? Anyone of you had similar problem? What was the solution in your case?

Excuse me, if there's already some answer for that on the list, but I couldn't find any.

Best regards,
-- 
Adam Strzelecki