lua-users home
lua-l archive

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

It was thus said that the Great bil til once stated:
> 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...

  luaL_tolstring() was added in Lua 5.2.  I'm thinking that tonumber()
wasn't modified to use it to avoid changing its behavior for existing code.