4 ms·
The section in question, "A quick aside on colon syntax", is referring to the code from the section above it, "Introduction to window movement": local win
by Slackwise 10y ago
The section in question, "A quick aside on colon syntax", is referring to the code from the section above it, "Introduction to window movement":
local win = hs.window.focusedWindow()
local f = win:frame()
win is presumable a copy ("instance") of the table hs.window created by focusedWindow().
Meaning hs.window.focusedWindow() returns a copy of the hs.window table.
With that being said, win.frame(win) would just be hs.window.frame(win), so you're also correct. It's just a poorly worded example explaining Lua's colon syntax feature.
- eridius 10y agoMore specifically, hs.window.focusedWindow() returns a userdata, with a metatable where the __index entry is the hs.window table. This means that looking up entries on the returned win object (e.g. looking up win.frame) will end up looking up the same key on the hs.window table. Or in other words, it's not literally a copy of the table, but it behaves like it. It's prototype-based inheritance, similar to JavaScript.
- Slackwise 10y agoI didn't actually look at the implementation of these functions and tables, but yea, I am fairly familiar with Lua and metatables from my days of working on WoW addons. As for JavaScript, my opinion is that Lua is everything JavaScript should have been: A clean, minimal, sanely designed, language. JavaScript on the other hand is nothing but mistakes piled upon mistakes. It's really disheartening to see JavaScript get shoved into places Lua fits better, like as Gnome Shell's scripting language. Oh well.
- martijn_himself 10y agoAh, thank you for clarifying this.