GLua library

GLua is an open source library which provides LUA programmers with classes and functions that mimic those available in GLSL, the OpenGL Shading Language.

GLua was especially designed as a base library for the Demoniak3D real-time engine, as it provides a consistent framework with GLSL shaders.


  • vec3.lua : 3D vectors and arithmetic
  • mat3.lua : 3D matrix and arithmetic
  • vec4.lua : 4D vectors and arithmetic
  • glsl.lua : generic functions following glsl prototypes as defined in book « OpenGL Shading Language » by Randi J. Rost
  • test.X.lua : unit test of module X

Usage & Samples:

Usage of the classes and functions is pretty straightforward.

Check the test.X.lua modules for more details or examples


GLua is available on under LGPL licence.

Implementation details:

  • the classes are based on class.lua, described on
  • glsl.lua offers generic function that work on LUA numbers and tables, and therefore all vector / matrix classes. It makes extensive use of functional programming to achieve this:
    • the « apply » function is defined as follows:
      --- applies a function to a table of parameters
      -- @param f : function to apply to each element in v
      -- @param v : (vector of) parameter(s) to f function
      -- @return : (vector of) result(s) of f(v)
      function apply(f,v)
      if type(v)=="number" then return f(v) end
      if type(v)=="table" then
      local res={}
      for i,x in ipairs(v) do res[i]=f(x) end
      return res
      error("apply "..f.."("..type(v)..") not implemented")
    • then, functions can easily be defined to support numbers, vectors, or matrices:
      function sin(rad)
      return apply(math.sin,rad)
  • dot product is implemented in 2 different ways :
    • through the « power » ^ operator in classes
    • as a generic dot(p1,p2) function in glsl.lua

No comments yet

Votre commentaire

Choisissez une méthode de connexion pour poster votre commentaire:


Vous commentez à l’aide de votre compte Déconnexion /  Changer )

Photo Facebook

Vous commentez à l’aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s

%d blogueurs aiment cette page :