createtable ex

From Onset Developer Wiki
Revision as of 01:19, 17 December 2019 by BlueMountains (talk | contribs) (Created page with "{{Info|Function|Client|1.0}} {{FuncDescription|Creates a new table and sets the metatable.}} {{FuncSyntax|createtable_ex(metatable)}} {{FuncParameters}} {{FuncParam|metatab...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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()