Hammerspoon hyper key1/15/2023 ![]() ![]() ![]() The latter is Lua’s object-method-call notation, and its effect is to pass the object on which the method is being called as an implicit first argument called self. You will notice that sometimes, functions contained within a module are called with a dot, and others with a colon. ![]() In practice, I’ve found myself using both notations somewhat exchangeably - feel free to use whichever you find most comfortable. Since the file variable is being passed as the first argument, you could rewrite this statement as file:match('/'). In string.match(file, '/'), we see the function notation used to call string.match(). This statement is equivalent to string.sub(file, -4). This invokes the string.sub() function, automatically passing the file variable as its first argument. In file:sub(-4), the colon indicates the object-oriented notation (see “Lua dot-vs-colon method access” below). Our first glimpse into the Lua string library, and the two ways in which it can be used: In this case we are not interested in the key in each iteration, just the value, so we assign the key to _, never to be used again. The _ variable, while not special per se, is used by convention in Lua for “throwaway values”. pairs() treats the files variable as an associative array, and returns in each iteration a key/value pair of its contents. We will learn more about Lua tables below, but they can be used to represent both regular and associative arrays. The pairs() function, which loops over a table. Going back to our example, we can also learn the following: This form loops the variable from the first to the last value, incrementing it by the given increment (defaults to 1) at each iteration. Lua includes all the common flow-control structures you might expect. Instead of detailing every structure, I will focus on the aspects that are most different or that are most likely to trip you up as you learn it. I assume you are a programmer who knows some other C-like language–if you already know C, Java, Ruby, Python, Perl, Javascript or some similar language, picking up Lua should be pretty easy. The purpose of this section is to give you a quick overview of the Lua features and peculiarities you may find most useful for developing Hammerspoon policies. It is easy to learn and use while having pretty powerful features, and is frequently used in games, but also in many other applications including, of course, Hammerspoon. Lua is a scripting language created in 1993, and focused from the beginning in being an embedded language for extending other applications. Along the way you will discover that Lua is a surprisingly powerful language. In this 2-part article I will show you the basics of Lua so you can read and write Hammerspoon configuration. Hammerspoon’s configuration files are written in Lua, so a basic knowledge of the language is very useful to be an effective user of Hammerspoon. One of the examples it comes with is what we're going to use: Change the meaning of the caps lock key.Just Enough Lua to Be Productive in Hammerspoon, Part 1 Karabiner-elements can create complex, powerful modifications. This rarely used four-chord combination will help to prevent stepping on other application's hotkeys, but it's by no means required.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |