lua-users home
lua-l archive

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

On Mon, Oct 02, 2006 at 07:05:17AM -0400, John Belmonte wrote:
> Doug Currie wrote:
> > So, my request is that Lua 5.2 either
> > - apply tostring() to non-string "%s" arguments of string.format(), or
> > - add a string.format option that applies tostring() to its argument,
> > and then performs the usual "%s" action.
> I'd like to see the first implemented by having lua_tostring honor
> __tostring, and perhaps adding a lua_rawtostring if there is really
> demand for it.

I don't think that can be done. Remember, lua_tostring converts the Lua
value at the given index to a string.

So, calling lua_tostring() on a value that had a __tostring metamethod
would remove it from the stack, replacing it with a string. Some people
already don't like auto-coercions between number and string, can you
imagine the trouble it would cause to have your user-data auto-coerced
to strings? :-(