lua-users home
lua-l archive

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


On Fri, Jun 30, 2006 at 10:54:01AM -0300, Roberto Ierusalimschy wrote:
> > [BTW: Whatever Lua 5.2 or 6.0 may look like, but may I suggest
> > redesigning or at least renaming the auto-coercive API calls?]
> 
> Only lua_tostring does auto-coercion. lua_tonumber (and lua_isnumber)
> does not modify the original object (at the cost of performing the
> conversion at every new call).

I lost a number of hours trying to get a table coercion working, I had
code like:

  if(lua_isstring())
	  lua_tostring()
  else if(lua_isnumber())
	  lua_tonumber()

I knew lua_tostring() would coerce the type of the value on the stack,
but it never occurred to me that lua_isstring() would return true if
it is NOT a string.

I guess this is just a gotcha for new lua users, and now that I know I
don't mind so much, but it sure surprised me.

Sam