Talk:OOP: Difference between revisions
Jump to navigation
Jump to search
m (add my sig properly) |
mNo edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Using "data tables" == | == Using "data tables" == | ||
(Contains content from multiple discussions) | (Contains content from multiple discussions) | ||
Think of '''element.data''' and '''element:getAllData'''. | Think of '''element.data''' and '''element:getAllData'''. | ||
Line 12: | Line 13: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
--[[User:Qais|qaisjp]] ([[User talk:Qais|talk]]) 21:24, 26 November 2014 (UTC) | --[[User:Qais|qaisjp]] ([[User talk:Qais|talk]]) 21:24, 26 November 2014 (UTC) | ||
== OOP Metatable Restructure == | |||
(Contains content from multiple discussions) | |||
* "right now set and get functions for variables are hidden, people can't easily manipulate them", "i wanna move them to the class table". | |||
* For example: | |||
<syntaxhighlight lang="lua"> | |||
Element.health = { __set = setElementHealth, __get = getElementHealth } | |||
-- lil_Toady originally suggested "set" and "get", but this could cause conflicts | |||
-- if users assigned variables to "set" and "get" for purposes other than this | |||
</syntaxhighlight> | |||
* This makes it "a bit more transparent" and will make inheritance better by applying inheritance on the class table directly | |||
** > this will be faster and much easier for users to implement their own classes | |||
<syntaxhighlight lang="lua"> | |||
Zombie = {...} | |||
setmetatable ( Zombie, { __index = Ped } ) | |||
</syntaxhighlight> | |||
--[[User:Qais|qaisjp]] ([[User talk:Qais|talk]]) 21:31, 26 November 2014 (UTC) |
Latest revision as of 21:31, 26 November 2014
Using "data tables"
(Contains content from multiple discussions) Think of element.data and element:getAllData.
- variables return a referenced table
- function returns a copy
element.data.moo = "foo" -- works! element:getAllData().moo = "foo" -- doesn't work! local elementData = element.data elementData.moo = "foo2" -- works!
--qaisjp (talk) 21:24, 26 November 2014 (UTC)
OOP Metatable Restructure
(Contains content from multiple discussions)
- "right now set and get functions for variables are hidden, people can't easily manipulate them", "i wanna move them to the class table".
- For example:
Element.health = { __set = setElementHealth, __get = getElementHealth } -- lil_Toady originally suggested "set" and "get", but this could cause conflicts -- if users assigned variables to "set" and "get" for purposes other than this
- This makes it "a bit more transparent" and will make inheritance better by applying inheritance on the class table directly
- > this will be faster and much easier for users to implement their own classes
Zombie = {...} setmetatable ( Zombie, { __index = Ped } )