Why equality operator returns true for two different NoteColumn instances?

I’m confused when working with NoteColumn userdata objects in the Renoise Lua API. I have two NoteColumn instances (note1 and note2) from different lines in the same track, and I expect them to be distinct instances with different memory addresses.

However, when I check their equality using the == operator, it returns true, which means that lua considers them equal, even though they should be different instances.

Here’s a code example and output:

local song = renoise.song()
local pattern = song.patterns[1]
local track = pattern.tracks[1]

local note1 = track:line(1).note_columns[1]
local note2 = track:line(2).note_columns[1]

print(note1)
print(note2)

print(note1 == note2)
print(rawequal(note1, note2))
C#40050....0000
D#30050....0000
true
false

Do you get the same result if you change these lines?:

local note1 = “StringOne”
local note2 = “StringTwo”

Here is the result:

StringOne
StringTwo
false
false

Seems note1 and note2 here are not string ‘types’ and contain the same object.

local note1 = track:line(1).note_columns[1]
local note2 = track:line(2).note_columns[1]

hth

Its userdata type renoise.DataColumn. For same instances it returns false.

The __eq(a, b) metatable methods for NoteColumn, EffectColumn, PatternLine, Pattern and Phrase are overloaded to check for content equality instead of checking for object identity. So it’s expected that this differs from rawequal which bypasses those metamethods.

There’s a bug NoteColumn and EffectColumn’s eq impl though. Must be in there since ages. They do check for != (for whatever reason). I’ll fix that for the next update.

3 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.