lua-users home
lua-l archive

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


2013/10/14 Andrew Starks <andrew.starks@trms.com>:

> So, when I see `tostring(x)`, I expect that there is also `tonumber`
> and `toboolean` and even `tonil` or totable, as nonsensical as the
> last two might seem/be.

'tostring' is there so that humans can read its output. 'tonumber' is
there because something else except a number can sometimes
be converted to a number. 'totable' is not there because a table
is a Swiss army knife, you don't know beforehand which blade
to use. Most of the other possibilities are in fact present in the
API. The full list is:

lua_toboolean
lua_tocfunction
lua_tointeger
lua_tointegerx
lua_tolstring
lua_tonumber
lua_tonumberx
lua_topointer
lua_tostring
lua_tothread
lua_tounsigned
lua_tounsignedx
lua_touserdata

This is misleading though since those 'to' functions actually
convert to C types.