lua-users home
lua-l archive

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


On Fri, Jul 10, 2015 at 9:28 AM, Choonster TheMage <choonster.2010@gmail.com> wrote:
On 11 July 2015 at 02:23, Борис Александров <boriscool007@gmail.com> wrote:
> http://prntscr.com/7r4ecw  It seems to me that lua compares table index and
> given value by address, not by _equal metamethod
>

Yes, this is explained in the manual:

The indexing of tables follows the definition of raw equality in the
language. The expressions a[i] and a[j] denote the same table element
if and only if iand j are raw equal (that is, equal without
metamethods).

http://www.lua.org/manual/5.3/manual.html#2.1

Every time you call lua_newuserdata, you're creating a new object
that's not raw equal to any other object.


Doing something like the following would demonstrate you can use userdata for table keys; it just seems like you're not using them the way you thought you were.

    for k,v in pairs(temp) do print(k,v) end

--
Brigham Toskin