lua-users home
lua-l archive

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


FYI this is solution I've used for OpenGL following your advise:

-- index metamethod removing gl prefix for funtions
-- and GL_ prefix for constants
setmetatable(M, { __index = function(t, n)
  local s
  -- all functions contain at least one small letter
  if n:find('[a-z]') then
    s = g['gl'..n]
  elseif n:find('^UT?_') then
    s = g['GL'..n]
  else
    s = g['GL_'..n]
  end
  rawset(t, n, s)
  return s
end })

And here's sample code that works for me:

  -- draw lights positions
  gl.UseProgram(0)
  gl.Disable(gl.LIGHTING)
  gl.Disable(gl.TEXTURE_2D)
  gl.PointSize(20)
  gl.PushMatrix()
  gl.Rotate(lightsRotation, unpack(lightsRotationAxis))
  gl.Begin(gl.POINTS)
  for l = 1, #lights do
    if lights[l].diffuse  then gl.Color4f(unpack(lights[l].diffuse))   end
    if lights[l].position then gl.Vertex4f(unpack(lights[l].position)) end
  end
  gl.End()
  gl.PopMatrix()
  gl.Enable(gl.TEXTURE_2D)
  gl.Enable(gl.LIGHTING)
  gl.UseProgram(program)

Cheers,
-- 
Adam Strzelecki