[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Default "tostring" for a table is an error-reporting function?
- From: Dirk Laurie <dirk.laurie@...>
- Date: Mon, 20 Feb 2017 15:55:13 +0200
We all know that Lua 5.3.4 is the brightest, shiniest Lua ever.
Here's just one reason why:
$ lua
Lua 5.3.4 Copyright (C) 1994-2017 Lua.org, PUC-Rio
> a=setmetatable({},{__name="Jedi Knight"})
> a
Jedi Knight: 0x2089510
However, the documentation of this feature in the Manual is scanty, even coy.
* In §2.4, it says:
"Some functions in the standard library (e.g., `tostring`) use other fields
in metatables for their own purposes."
* In the entry for luaL_newmetatable in §5.1, it says:
"(The entry __name is used by some error-reporting functions.)"
Now one _could_ make out a case that anything containing an actual
memory address is an error-reporting function ...
But for a feature as popular as this one is sure to be, maybe just a tiny
bit extra in §2.4?
"Some functions in the standard library use other fields in metatables for
their own purposes. E.g., `tostring` replaces `table`, `userdata` etc. by the
value of `__name`."