Skip to main content

setmetatable

Function setmetatable 

Source
pub fn setmetatable(t: table, metatable: option<table>) -> table
Expand description

Sets the metatable for the given table. If metatable is nil, removes the metatable of the table. If the original metatable has a __metatable field, raises an error.

Returns t. (To change the metatable of other types from Lua code, you must use the debug library.)

§Examples

local parent = { greet = function() print("hi") end }
local child = setmetatable({}, { __index = parent })
child.greet()    --> hi   (found through __index)