Metatable

From GMod Wiki

Jump to: navigation, search
Stub.pngThis article is a stub.
You can help the GMod Wiki by expanding it.

A metatable is, like the word metatable means, "a table about a table". Metatables are used to store information about tables and contain methods that can be used to change the behavior of tables.

---

Creating a metatable

 
// Start your metatable of by declaring a table
local ExampleMeta = {}
// Add an index to it
ExampleMeta.__index = ExampleMeta.__index
 
// This function will do the work to create a metatable
function ExampleMeta:Constructor()
	local Obj = {};
	// Actually create our metatable
	setmetatable(Obj,self);
	// return the table
	return Obj;
end
 
// This is just an example function
function ExampleMeta:MyFunc( a, b )
	return math.Round((a * b /) 100)
end
 
function ExampleMeta:CreateMeta()
	return ExampleMeta:Constructor()
end
 
Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox