lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

>From: "John Belmonte" <>
>I've been studying Lua and I noticed that the concept of tags was not
>present in the language at the time the SPE paper was written.  Is
>there any information available on the designers' reasoning for adding

The notion of tags was always present in Lua, but only used for userdata until
version 3.0, which introduced "tag methods" to replace "fallbacks".

While, as you point out, everything could in principle be done with fallbacks,
the tag method meta-mechanism is much cleaner, because it avoids clashes
between different fallbacks.

For instance, if you might want to have different schemes for inheritance.
With fallbacks, you'd have to remember to chain the fallbacks for the two
schemes, which was a hassle and inefficient too.  Tag methods ended this
confusion by grouping the fallbacks correspoding to a given tag in a way that
methods for different tags do not interfere with each other.

If you're happy with fallbacks, then see lua/etc/setfallback.lua for an
implementation of fallbacks on top of tag methods.