aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-11-08 15:45:55 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-11-08 15:45:55 -0300
commit679dc72c08a7c563a0c3f463332d6f22d573a106 (patch)
tree8b0c2165b46d729225ec6f65e9cd673e2954c517
parent1499680f9e3d694462ac645ed8162f310509c64c (diff)
downloadlua-679dc72c08a7c563a0c3f463332d6f22d573a106.tar.gz
lua-679dc72c08a7c563a0c3f463332d6f22d573a106.tar.bz2
lua-679dc72c08a7c563a0c3f463332d6f22d573a106.zip
Using 'metavalues' for "metamethods" that are not methods
Several "metamethods" are not required to be methods (functions), so it seems clearer not to call them metamethods. The manual now uses the word 'metavalue' for those values.
-rw-r--r--manual/manual.of47
1 files changed, 26 insertions, 21 deletions
diff --git a/manual/manual.of b/manual/manual.of
index 00ab4cd5..7b5b9385 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -306,11 +306,14 @@ Lua calls this function to perform the addition.
306 306
307The key for each event in a metatable is a string 307The key for each event in a metatable is a string
308with the event name prefixed by two underscores; 308with the event name prefixed by two underscores;
309the corresponding values are called @def{metamethods}. 309the corresponding value is called a @def{metavalue}.
310For most events, the metavalue must be a function,
311which is then called a @def{metamethod}.
310In the previous example, the key is the string @St{__add} 312In the previous example, the key is the string @St{__add}
311and the metamethod is the function that performs the addition. 313and the metamethod is the function that performs the addition.
312Unless stated otherwise, 314Unless stated otherwise,
313metamethods should be function values. 315a metamethod may in fact be any @x{callable value},
316which is either a function or a value with a @id{__call} metamethod.
314 317
315You can query the metatable of any value 318You can query the metatable of any value
316using the @Lid{getmetatable} function. 319using the @Lid{getmetatable} function.
@@ -468,19 +471,19 @@ Behavior similar to the less than operation.
468The indexing access operation @T{table[key]}. 471The indexing access operation @T{table[key]}.
469This event happens when @id{table} is not a table or 472This event happens when @id{table} is not a table or
470when @id{key} is not present in @id{table}. 473when @id{key} is not present in @id{table}.
471The metamethod is looked up in the metatable of @id{table}. 474The metavalue is looked up in the metatable of @id{table}.
472 475
473Despite the name, 476The metavalue for this event can be either a function, a table,
474the metamethod for this event can be either a function or a table. 477or any value with an @id{__index} metavalue.
475If it is a function, 478If it is a function,
476it is called with @id{table} and @id{key} as arguments, 479it is called with @id{table} and @id{key} as arguments,
477and the result of the call 480and the result of the call
478(adjusted to one value) 481(adjusted to one value)
479is the result of the operation. 482is the result of the operation.
480If it is a table, 483Otherwise,
481the final result is the result of indexing this table with @id{key}. 484the final result is the result of indexing this metavalue with @id{key}.
482This indexing is regular, not raw, 485This indexing is regular, not raw,
483and therefore can trigger another metamethod. 486and therefore can trigger another @id{__index} metavalue.
484} 487}
485 488
486@item{@idx{__newindex}| 489@item{@idx{__newindex}|
@@ -488,18 +491,20 @@ The indexing assignment @T{table[key] = value}.
488Like the index event, 491Like the index event,
489this event happens when @id{table} is not a table or 492this event happens when @id{table} is not a table or
490when @id{key} is not present in @id{table}. 493when @id{key} is not present in @id{table}.
491The metamethod is looked up in @id{table}. 494The metavalue is looked up in the metatable of @id{table}.
492 495
493Like with indexing, 496Like with indexing,
494the metamethod for this event can be either a function or a table. 497the metavalue for this event can be either a function, a table,
498or any value with an @id{__newindex} metavalue.
495If it is a function, 499If it is a function,
496it is called with @id{table}, @id{key}, and @id{value} as arguments. 500it is called with @id{table}, @id{key}, and @id{value} as arguments.
497If it is a table, 501Otherwise,
498Lua does an indexing assignment to this table with the same key and value. 502Lua repeats the indexing assignment over this metavalue
503with the same key and value.
499This assignment is regular, not raw, 504This assignment is regular, not raw,
500and therefore can trigger another metamethod. 505and therefore can trigger another @id{__newindex} metavalue.
501 506
502Whenever there is a @idx{__newindex} metamethod, 507Whenever a @idx{__newindex} metavalue is invoked,
503Lua does not perform the primitive assignment. 508Lua does not perform the primitive assignment.
504If needed, 509If needed,
505the metamethod itself can call @Lid{rawset} 510the metamethod itself can call @Lid{rawset}
@@ -760,7 +765,7 @@ In any case, if either the key or the value is collected,
760the whole pair is removed from the table. 765the whole pair is removed from the table.
761The weakness of a table is controlled by the 766The weakness of a table is controlled by the
762@idx{__mode} field of its metatable. 767@idx{__mode} field of its metatable.
763This field, if present, must be one of the following strings: 768This metavalue, if present, must be one of the following strings:
764@St{k}, for a table with weak keys; 769@St{k}, for a table with weak keys;
765@St{v}, for a table with weak values; 770@St{v}, for a table with weak values;
766or @St{kv}, for a table with both weak keys and values. 771or @St{kv}, for a table with both weak keys and values.
@@ -3836,7 +3841,7 @@ Similar to @Lid{lua_gettable}, but does a raw access
3836Pushes onto the stack the value @T{t[n]}, 3841Pushes onto the stack the value @T{t[n]},
3837where @id{t} is the table at the given index. 3842where @id{t} is the table at the given index.
3838The access is raw, 3843The access is raw,
3839that is, it does not invoke the @idx{__index} metamethod. 3844that is, it does not use the @idx{__index} metavalue.
3840 3845
3841Returns the type of the pushed value. 3846Returns the type of the pushed value.
3842 3847
@@ -3849,7 +3854,7 @@ Pushes onto the stack the value @T{t[k]},
3849where @id{t} is the table at the given index and 3854where @id{t} is the table at the given index and
3850@id{k} is the pointer @id{p} represented as a light userdata. 3855@id{k} is the pointer @id{p} represented as a light userdata.
3851The access is raw; 3856The access is raw;
3852that is, it does not invoke the @idx{__index} metamethod. 3857that is, it does not use the @idx{__index} metavalue.
3853 3858
3854Returns the type of the pushed value. 3859Returns the type of the pushed value.
3855 3860
@@ -3885,7 +3890,7 @@ and @id{v} is the value on the top of the stack.
3885 3890
3886This function pops the value from the stack. 3891This function pops the value from the stack.
3887The assignment is raw, 3892The assignment is raw,
3888that is, it does not invoke the @idx{__newindex} metamethod. 3893that is, it does not use the @idx{__newindex} metavalue.
3889 3894
3890} 3895}
3891 3896
@@ -3899,7 +3904,7 @@ and @id{v} is the value on the top of the stack.
3899 3904
3900This function pops the value from the stack. 3905This function pops the value from the stack.
3901The assignment is raw, 3906The assignment is raw,
3902that is, it does not invoke @idx{__newindex} metamethod. 3907that is, it does not use the @idx{__newindex} metavalue.
3903 3908
3904} 3909}
3905 3910
@@ -6275,7 +6280,7 @@ Returns a boolean.
6275 6280
6276@LibEntry{rawget (table, index)| 6281@LibEntry{rawget (table, index)|
6277Gets the real value of @T{table[index]}, 6282Gets the real value of @T{table[index]},
6278without invoking the @idx{__index} metamethod. 6283without using the @idx{__index} metavalue.
6279@id{table} must be a table; 6284@id{table} must be a table;
6280@id{index} may be any value. 6285@id{index} may be any value.
6281 6286
@@ -6291,7 +6296,7 @@ Returns an integer.
6291 6296
6292@LibEntry{rawset (table, index, value)| 6297@LibEntry{rawset (table, index, value)|
6293Sets the real value of @T{table[index]} to @id{value}, 6298Sets the real value of @T{table[index]} to @id{value},
6294without invoking the @idx{__newindex} metamethod. 6299without using the @idx{__newindex} metavalue.
6295@id{table} must be a table, 6300@id{table} must be a table,
6296@id{index} any value different from @nil and @x{NaN}, 6301@id{index} any value different from @nil and @x{NaN},
6297and @id{value} any Lua value. 6302and @id{value} any Lua value.