Revision Difference
Global.AccessorFunc#560188
<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="182-L220">lua/includes/util.lua</file>
<args>
<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 = Player( 1 )
ply:SetFooBar(true)
⤶
print(ply:GetFooBar())⤶
⤶
meta:SetFooBar(true)
⤶
print(meta:GetFooBar())
</code>
<output>true</output>
</example>