3 ms·
The def self.foo(arg): ... variant GvR mentions reminds me of one of the many ways you can implement OO-style in Lua: function object.method(arg) ... end
by bayareaguy 18y ago
The
def self.foo(arg): ...
variant GvR mentions reminds me of one of the many ways you can implement OO-style in Lua:
function object.method(arg) ... end
- felixmar 18y agoF# uses it too for adding OO members to types: type Foo = ... member self.Bar(arg) = 'self' can be named as you like.
- silentbicycle 18y agoI think you mean function object:method(arg) ... end, if you're assuming that object will be passed (as "self") implicitly. The colon is the difference from normal map indexing. I much prefer Lua's solution for this over Python's (and I'm also coming to strongly prefer prototype-style OO, in general).
- bayareaguy 18y agoIndeed, you are correct. function obj:method(arg) .. end is the same as function obj.method(obj,arg) .. end I think the reason I mentioned the latter is I generally use Lua closures to code the way Eckel preferrs. "Objects are a poor man's closures" -- Norman Adams