lua-users home
lua-l archive

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


On Mon, Oct 02, 2006 at 01:35:36PM -0500, Rici Lake wrote:
> I don't think that's really necessary. It can easily be written 
> (although the following code has not actually been tested):

This wouldn't be used by libraries, though: you'd have to modify them to
use it.

I'd like luaL_typerror (or luaL_typename) to try a __type metamethod.
Currently, I have to modify it, so "number expected, got table" can
become "number expected, got Sprite".

> const char *my_pushstringvalue (luaState *L, int obj, size_t *plen) {
>   switch (lua_type(L, obj)) {
>     case LUA_TSTRING:
>     case LUA_TNUMBER:
>       lua_pushvalue(L, obj);
>     default: {
>       if (0 == luaL_callmeta(L, obj, "__string"))
>         return NULL;

Maybe for number types, too, for custom number conversions.

-- 
Glenn Maynard, wishing for the end of 0 == n()