Top  Previous  Next

This namespace holds the unified class implementation for Girder. It is suggested you follow this class structure when building your own scripts.


The basic structure of a new class is as follows

local Base = require('Class') -- the base class for this object.


module (...)




local privateNumber = 1


local privateFunction = function(self )




function init ( self, param1, param2 )

 print(param1, param2)




function deinit( self )




If you want to subclass this new class simply require it on the first line and assign it to the base variable. Any public variables or functions will be part of the public interface of the class. Any local functions or variables will be private.

If we saved this class under the name "example/test.lua" we could use the following code to instantiate the class:

local ExampleClass = require('example.test')

local exampleObject = ExampleClass:new( param1, param2 )

As you can see param1 and param2 will be passed to the init function of our class. You can have as many of these as you like. Also note that the class names are capitalized and the variable names start with a small letter. This helps keep the Class vs. instantiated objects clear.