super(object)

Get the ancestor of an object or instance.

The super() function permits you to access ancestor methods, fields and properties.

Parameters

object

An object (as defined by the Object() function) or an instance.

Return value

This function returns the ancestor object, or nil if no ancestor is found.

Example

Polygon = Object {} -- Defines a new Object Polygon -- Defines a constructor for the Polygon Object function Polygon:constructor(n) -- Defines a new filed 'sides' self.sides = n end Square = Object (Polygon) -- Defines a new Object Square, inheriting from Polygon -- Defines a constructor for the Square Object (with 4 sides) function Square:constructor() -- Don't rewrite previous code, just use super() to call the Polygon constructor -- to initialize the sides field with the value of 4 super(self).constructor(self, 4) end -- Should print true print(super(Square) == Polygon) -- Should print 4 print(Square().sides)