lua-users home
lua-l archive

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


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...