Revision Difference
Global.AccessorFunc#514830
<function name="AccessorFunc" parent="Global" type="libraryfunc">⤶
<description>⤶
Adds simple Get/Set accessor functions on the specified table.&lt;br /&gt;⤶
Can also force the value to be set to a number, bool or string.⤶
</description>⤶
<realm>Shared and Menu</realm>⤶
<file line="175-L195">lua/includes/util.lua</file>⤶
<args>⤶
<arg name="tab" type="table">The table to add the accessor functions too.</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>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.GetByID(1)⤶
ply:SetFooBar(true)⤶
⤶
print(not ply:GetFooBar())⤶
</code>⤶
<output>false</output>⤶
⤶
</example>