• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Lua] Wrap every called class function with another function

Status
Not open for further replies.
Level 15
Joined
Feb 7, 2020
Messages
398
I can't wrap my head around what metamethod to use for this, or how the code would look, after much trial and error:

I'd like to take a table, say "myClass", and wrap every method called from it with another function (that preserves the original function's arguments when used in the wrapper).

e.g.
Lua:
myObj = myClass:new()
myObj:doSomeStuff(someArg)
myObj:doSomeOtherStuff(myArg)
myObj:doSomeMoreStuff(myOtherArg)
-- do a hidden wrap of each i.e. someWrapper(doSomeStuff(someArg)) and so on, without having to WET

If that made sense, do any Lua gurus have an example of this concept available? The online tutorials I tried to follow were a bit unworldly (incrementing random integers, etc.).
 
Last edited:
Level 17
Joined
Apr 27, 2008
Messages
2,455
Maybe i missunderstand what you want or even i'm totally wrong (my lua knowledge is basically limited to the read of the 5.3 manual)

From what i understood, user defined metatables methods are only called if there is no such method available in the parent class.
So i don't think it's possible, else i will read further and learn :p
 
Level 15
Joined
Feb 7, 2020
Messages
398
Maybe i missunderstand what you want or even i'm totally wrong (my lua knowledge is basically limited to the read of the 5.3 manual)

From what i understood, user defined metatables methods are only called if there is no such method available in the parent class.
So i don't think it's possible, else i will read further and learn :p
I think I finally found this same answer on a less-opaque tutorialpoint page. I believe you are correct.

:peasant-sad:
 
Status
Not open for further replies.
Top