Revision Difference
Global.AccessorFunc#547757
<function name="AccessorFunc" parent="Global" type="libraryfunc">
<description>
Adds simple Get/Set accessor functions on the specified table.
Can also force the value to be set to a number, bool or string.
</description>
<realm>Shared and Menu</realm>
<file line="177-L219">lua/includes/util.lua</file>
<args>
<arg name="tab" type="table">The table to add the accessor functions too.</arg>
<arg name="tab" type="table">The table to add the accessor functions to.</arg>
<arg name="key" type="any">The key of the table to be get/set.</arg>
<arg name="name" type="string">The name of the functions (will be prefixed with Get and Set).</arg>
<arg name="force" type="number" default="nil">The type the setter should force to (uses <page>Enums/FORCE</page>).</arg>
</args>
</function>
<example>
<description>Adds the GetFooBar and SetFooBar functions to the Player metatable and then uses them.</description>
<code>
local meta = FindMetaTable("Player")
AccessorFunc(meta, "foo_bar", "FooBar", FORCE_BOOL)
local ply = Entity( 1 )
ply:SetFooBar(true)
print(not ply:GetFooBar())
</code>
<output>false</output>
</example>