lua-users home
lua-l archive

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


It was thus said that the Great Duane Leslie once stated:
> Hi,
> 
> Would it be possible to add a `__next` metamethod to allow the `pairs`
> behaviour to be inferred in the same way that now the `ipairs`
> behaviour is inferred from the `__index` metamethod.  I have looked
> through some discussions of this in the mailing list in the past and
> it seems to have been that the `__pairs` metamethod was preferred
> because it was more powerful (it allows the construction of a `next`
> equivalent function as a closure with additional information).
> 
> The problem I have is that I have situations where the `next()`
> function makes more sense to iterate over some userdata objects than
> using `for ... pairs` but I cannot make the behaviour of these two
> methods equivalent.
> 
> The idea would be to have the situation where I could define just the
> `__next` metamethod, and this would be used as the result of the call
> to the `next` function, and so in turn would imply that `pairs` would
> call my `__next` metamethod through the standard `next` function.

  My own archives of the Lua mailing list go back to October of 2009, and
the earliest record I found of __next was on the 15th of January, 2010:

	http://lua-users.org/lists/lua-l/2010-01/msg00935.html

  I'm not saying your idea is bad Duane, but I am using it as a springboard
for the Giant List of Proposed Lua Metamethods since October 2009!  The
following list is probably incomplete and may have some inaccuracies in it,
and I have no information other than the name of the method (I did not
record who first proposed it or even what the final verdict was).  Also, I
only recorded the first instance of a method; not every time it showed up is
listed.  I'm just thinking it might be fun to see how "obvious" some of
these are (my personal favorite: __athashdollarpercentbangbangsplat from
2013).

  You have been warned.

  -spc (And yes, work has been a bit slow lately ... )

===[ Proposed ]====

2009
	__clone
	__export
	__field
	__getindex
	__help
	__immediate_gc
	__iter
	__mcall
	__metaindex
	__methindex
	__methods
	__objindex
	__old
	__oldindex
	__persist
	__property
	__proxy
	__useindex

2010
	__bit_and
	__bit_or
	__bit_xor
	__buildattr
	__environment
	__hash
	__id
	__next
	__sanitize
	__tojson
	__tonumber
	__unm
	__usedindex

2011
	__assign
	__bases
	__boolean
	__class
	__comment
	__debug
	__declared
	__delindex
	__from
	__ge
	__get
	__getindex
	__getmetatable
	__getnew
	__getters
	__gt
	__has_*
	__hasheq
	__inherited
	__init
	__initialized
	__ivars
	__jsonorder
	__jsontype
	__killindex
	__method
	__mymetamethod
	__ne
	__oid
	__online
	__recv
	__remindex
	__seen__
	__send
	__set
	__setindex
	__setmetatable
	__setnew
	__shared
	__string
	__syntax
	__timeout
	__tobuffer
	__type
	__user_init
	__xxx

2012
	__eval
	__immutable
	__intdiv
	__istype
	__mark
	__mutate_asn
	__newcall
	__newslice
	__not
	__proto__
	__slice
	__typeinfo
	__typename
	__weak
	__xor

2013
	__athashdollarpercentbangbangsplat
	__classname
	__finalize
	__has
	__in
	__instancedata
	__interface
	__metadata
	__plus
	__produce
	__setindexnil
	__setmethod
	__special_method_name
	__y_*
	__z_*

2014
	__append
	__clear
	__colon
	__coroutine
	__does_not_use_methods
	__function
	__iflags
	__inext
	__iogetline
	__is_luajson
	__key
	__length
	__multiindex
	__mykey
	__newmultiindex
	__number
	__parent
	__rawget
	__rawset
	__stringmetatable
	__stringmt
	__t
	__table_printer
	__thread
	__tobool
	__totable
	__unpack
	__uses_methods
	__wipe
	__xcopy

2015
	__bson
	__cbor
	__close
	__collision_check
	__json
	__move
	__parse
	__repr
	__serialize
	__totable
	__unindex

2016
	__copy