[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Why is luaL_tolstring (with meta support) only used for formatted output?
- From: bil til <biltil52@...>
- Date: Sat, 27 Aug 2022 16:51:31 +0200
There are two functions in the Lua C code, which are quite similar:
lua_tolstring and luaL_tolstring
As I see it, the main difference is that luaL_tolstring checks the
meta functions, whether "__tostring" meta is found (and then uses it).
For any constructs using metatables, this of course is a very nice and
useful behaviour, but this seems to be used ONLY for formatted output
(e. g. pring / string.format / error messages).
Other very useful functions like especially tonumber in baselib check
only lua_tolstring (so NO meta checking).
Is this only to save some microseconds speed (I can understand that
there might by Lua software, in which tonumber is used very
frequently), or are there some deeper dangers, if luaL_tostring would
also be used in tonumber?
... just curiosity, I can live with this - I just would be interested
in the deeper reason for this...