#dumb question, solved myself.
23 messages · Page 1 of 1 (latest)
it was a question, not a problem
here i'll rewrite it:
i was wondering why oop was usually done with metatables, rather than just cloning a table, since metatables are generally slower.
i realized that the reason was because cloning the tables would create multiple of the same exact same function, taking up more memory. aswell as the performance boost this being very very very insignificant. (assuming you're not creating more than 1 of the object, after that it would take up more memory anyway)
how is oop done with metatables
can you explain
this seems really interesting
using the __index metamethod?
i'm sorry can you explain this please
do some research on metatables
i'll just give you the basics rq
metatables are essientally just fancy tables
they're created with
setmetatable(tbl, metatable)
a metatable is just another table with 'metamethods'
metamethods are used for custom functionality
there's metamethods for things like addition, converting to a string, etc
here's the docs if you wanna have a read https://create.roblox.com/docs/luau/metatables
im pretty sure the main reason is because most programmers are old
since lua isnt oop, metatables are used to mimic it
without a metatable, it would work the same but it wouldnt be similar enough to oop to be considered oop
if that makes sense
An alternative look at the common OOP pattern in Lua programming.
0:00 Intro
0:44 Person Class
1:15 Sending an OOP instance over the wire
4:37 Hot Take
5:14 The Fix
6:53 Types & Ditching Constructor
8:10 Other Thoughts
10:03 Summary