Quantcast WoWInterface - View Single Post - metatables help to understand?
View Single Post
05-14-19, 09:51 PM   #1
urakkaamyx
A Murloc Raider
Join Date: May 2019
Posts: 8
metatables help to understand?

So i've been looking into meta tables, but i feel like use it would create more unnecessary code...
...unless i'm looking at it wrong.

So in the example i'm showing i'm wandering if i'm using it correctly.

can someone give a brief run down on why you need -or- should use metatables

Lua Code:
  1. local SomeClass = {}
  2.  
  3. metatable = {}
  4. setmetatable(SomeClass, metatable)
  5.  
  6. function SomeClass:DoSomething ( table, ... )
  7.     return "Something Happens"
  8. end
  9.  
  10. function metatable:__call( table, ... )  
  11.     return SomeClass:DoSomething(table, ... )
  12. end


this being like this, i can just print(SomeClass()) and it would result in "Something Happens" ... buut I fell like itd be simplier to just do a static call print(SomeClass: DoSomething()) ... Space in ther to prevent emoticon and static may be the wrong term (php dev background)

Last edited by urakkaamyx : 05-14-19 at 10:03 PM. Reason: added more explaination
  Reply With Quote