[migrated]
the colon is just syntactic sugar. in above case, calling midi_signal:note_on(60,127) is the same as midi_signal.note_on(midi_signal, 60,127).
[context: midi_signal = midi.connect()]
in the libs, we always “declare instance methods” with a colon, and for “class methods” that don’t require an instance argument, we don’t pass one and therefore don’t use the colon.
the alternative would be to never use the colon and always show the instance arg explicitly. this would be non-idiomatic.
in other words, these functions are equivalent:
f = { x = 10 }
function f.inc(o)
o.x = o.x + 1
print(o.x)
end
function f:inc2()
self.x = self.x + 1
print(self.x)
end
and either function can be called with either syntax, regardless of how they’re defined:
> f.inc(f)
11
> f:inc2()
12
> f.inc2(f)
13
> f:inc()
14
AFAIK we never use the first form in the norns libs.
(maybe one thing that is confusing here is that you also have midi_signal.event = blabla. but .event is a field in the “instance” table, that stores a reference to a function.)
@andrew actually now that i’m looking, maybe what you mean is that it’s not completely at all obvious from the API docs which functions are instance methods and which are static functions. i’ve tried to explicitly state when a function is static, but i don’t know offhand how to explicitly tell LDoc to treat them differently.
update, oh. we should be using @classmod instead of @module. then it looks good. woops. i opened an issue.