lua-users home
lua-l archive

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


2016-02-18 22:46 GMT+02:00 Ivan <ivan@sleepyiora.pw>:
> I’m trying to create my own type (for complex numbers) and
> use it within Lua scripts.

This has been done by Luiz himself (Google: complex lua lhf).

> It’s okay but the problem is that in some messages this type is
> denoted as ‘userdata’ which looks ugly. I have found that if type’s
> metatable has __name field, that it’s value is used as a type name.
> Unfortunately this key is not used everywhere, e.g. pairs(complex)
> still uses ‘userdata’ name. Is there a way I can make Lua to use
> custom type name?

Under Lua 5.3.2 with Luiz's complex, I get:

> z=complex.new(0,1); pairs(z)
stdin:1: bad argument #1 to 'pairs' (table expected, got complex number)

So I can't reproduce your result.

The manual says only:

    The entry __name is used by some error-reporting functions.

The word "some" usually means "at least one but not all". I suspect
that the vagueness is deliberate, and if you could provide a list of
which error messages you would like to have included too, some (!)
might get into Lua 5.3.3.