You are here: Lua Scripting Resources eGuide > Lua Scripting API Reference Guide > Class Library > class

4.1 class

class([parent_class])

Returns a new class. If a parent class is specified, the new class inherits the methods of the parent class.

Listing 4.1: Class Library Example

Widget = class()

function Widget:init() ... end

Button = class(Widget)

function Button:init() ... end

With these definitions, when the script calls Button(), a new Button is created. The Button:init() function is called to initialize the button, and the newly minted Button object is returned as the function result of the call.

Class Button in this example inherits all the methods and class variables defined in class Widget.

Class Button can override any methods of its parent class.

Introduced in platform.apiLevel = '1.0'