lua-users home
lua-l archive

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


Am 02.02.2016 um 18:42 schrieb Roberto Ierusalimschy:
>> In the remainder of the manual, metamethods are marked-up as
>> 
>>   * two leading underscores
>>   * followed by the event name
>>   * within <code> tags.
>> 
>> How can that be grep'ed or searched with an editor for metamethods?
> 
> A search for '__' works pretty well for me.

Sanitizing (which grep can't) the results of a search for pattern __%w+
in the manual gives me only 16 [1] out of the ca. 30 [2] metamethods
available.  Yes, you can look-up metamethods in secondary documentation.
 But since that is neither guaranteed to be up-to-date nor to be
correct, I'd appreciate primary documentation covering the use-case of
quickly looking-up metamethods, i.e., to include a list of all metamethods.

Best regards,
Stephan Hennig

[1]

1       __add
2       __call
3       __concat
4       __eq
5       __gc
6       __index
7       __ipairs
8       __le
9       __len
10      __lt
11      __metatable
12      __mode
13      __newindex
14      __pairs
15      __tostring
16      __unm

Here's a script that matches pattern __%w+ against stdin and outputs a
sorted list:

local metamethods = {}
-- Find unique matches.
for line in io.lines() do
   for name in line:gmatch('__%w+') do
      metamethods[name] = true
   end
end
-- Sort and output all matches.
local a = {}
for name in pairs(metamethods) do
   table.insert(a, name)
end
table.sort(a)
for i, name in ipairs(a) do
   print(i, name)
end


[2] A thorough list of metamethod has been published in this mail
<URL:http://lua-users.org/lists/lua-l/2015-04/msg00033.html>.  A
Markdown version of the same list can be found at
<URL:https://github.com/starius/helpme/blob/master/lua-metamethods.md>.