lua-users home
lua-l archive

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


I was actually thinking of extending ffi.cdef to do that for me:

local defs = ffi.cdef[[...]]

then defs contains all your definitions, like:

{
  functions = {
    glBlah = { [0]="void", "int", "int" },
  },
  enums = {
  },
}

etc.

From there I'll export some table that contains the proper defs.

On 1/19/2012 9:09 AM, Adam Strzelecki wrote:
Hi,

It would be great ffi.load could let use specify name transformation function (callback):

   -- function removing gl prefix and changing case,
   -- returning transformed name or nil if we want to skip some symbol
   -- i.e. glDrawArrays ->  drawarrays
   local function transform(name, type) […]

   local gl = ffi.load("GL", false, transform)

So it allows us to write:

   gl.begin(gl.VERTEX)

Instead of:

   gl.glBegin(gl.GL_VERTEX)

(Having that we change all cdef GL_VALUE enum entries into VALUE entries)

WDYT? Would such extension sacrifice performance? It would save a lot of typing for sure especially for libs using long prefixes.

Also it would be nice if we could enumerate symbols specified by cdef present in particular library. This would give us possibility also to check presence of particular symbol without raising error.

   for obj, name, type in ffi.symbols(gl) do
     -- do something
   end

Regards,