-
Notifications
You must be signed in to change notification settings - Fork 0
Usage of periods and colons in method calls
Jeroen Broks edited this page Aug 11, 2020
·
1 revision
Lua normally requires the use of a colon for this.
myclass = {
mymethod = function(self) return tostring(self) end
}
myclass.mymethod() -- returns nil
myclass:mymethod() -- returns the memory address of "myclass"
myclass.mymethod(myclass) -- Is exactly the same as myclass:mymethod. The : was just syntaxic sugar to get you from needless typing.
This get up is still supported by Neil, but only for interfacing code actually written in Lua from the start. Strings and tables can also still do great by them.
a = "Hello World"
print(a:upper()) -- Outputs "HELLO WORLD"
print(a:lower()) -- Outputs "hello world"
When you do this in Neil your code must look like this:
string a = "Hello World"
print(a:upper()) // Outputs "HELLO WORLD"
print(a:lower()) // Outputs "hello world"
The stuff defined with the Neil class system does NOT require that.
group MyClass
void Check()
return Lua.tostring(self)
end
end
Init
MyClass.Check() // period.... no colon
end
And yes the use of the period will also live through if classes created in Neil are exported into pure Lua. Neil has been set up to use periods only in order not to cause any needless bugs due to mixing up periods and colons. However, since Neil is set up to be able to interface with pure Lua, the use of colons could not entirely get abolished, as the pure Lua stuff is still bound to that.