createtable ex

From Onset Developer Wiki
createtable ex

Type: Function
Context: Client
Introduced: v1.0

Description

Creates a new table and sets the metatable.

Syntax

createtable_ex(metatable)

Parameters

  • metatable
    The metatable to set.

Return Value

  • Returns a new table with the desired metatable.

Example

Timer = {}
Timer.name = "Timer"
Timer.__index = Timer
Timer.prototype = {}
Timer.prototype.__index = Timer.prototype
Timer.prototype.constructor = Timer
function Timer.new(...)
    local self = createtable_ex(Timer.prototype)
    self:____constructor(...)
    return self
end
function Timer.prototype.____constructor(self, id)
    self.id = id
    print("constructor ", self.id)
end
function Timer.prototype.pause(self)
    print("pause ", self.id)
end
function Timer.prototype.unpause(self)
    print("unpause ", self.id)
end
function Timer.prototype.destroy(self)
    print("destroy ", self.id)
end

t = Timer.new(12)
t.pause()