Byrth / Lua-Byrth

Lua Addons and Scripts
3 stars 2 forks source link

GearSwap - syntax clarification #442

Closed kokyrone closed 7 years ago

kokyrone commented 7 years ago

What's the T do here? T{'Idle','Resting'}:contains(new) Versus or compared to the S here? S{'Warp','Warp II'}:contains(spell.english)

I'm assuming this was maybe covered in "Special tables" in the Lua section of the GearSwap tutorial?

Byrth commented 7 years ago

T and S are both "constructors" for the tables and sets libraries that Arcon wrote (windower/addons/libs/tables.lua and windower/addons/libs/sets.lua). There is, additionally, a Lists option that is used sometimes (windower/addons/libs/lists.lua)

In Lua, these two statements are functionally identical:

So your examples are calling functions T() and S() (and L() for the lists library) that construct and return a customized Lua table with added methods (like :contains()).

These constructors are used for conceptual simplicity rather than efficiency. I'm not sure they're much more computationally efficient than manually making tables as I describe above, but modern hardware is going to make any minor inefficiencies they introduce nearly undetectable in most situations.