lua-users home
lua-l archive

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


On Jul 8, 2012 11:26 PM, "Patrick Donnelly" <batrick@batbytes.com> wrote:
>
> On Mon, Jul 9, 2012 at 12:10 AM, Rena <hyperhacker@gmail.com> wrote:
> > +1, I've expressed a few times that functions expecting strings as input
> > should call [__]tostring. It'd make life easier when dealing with objects
> > that may or may not be strings but can be converted to them. The C API is
> > where this bugs me most, as few libraries bother to do it themselves.
>
> Lua 5.2 is better about this. Lua tostring() is simply a wrapper
> around luaL_tostring. [The auxiliary library is appropriate for this
> coercion I think.] So if a C library wants to coerce an input into a
> string, luaL_tostring is basically what you want. No need to
> lua_getglobal(L, "tostring").
>
> --
> - Patrick Donnelly
>

True, but lua_tostring and lua_isstring ignore metamethods. (But will accept numbers...)