![]() However, rep can take any of the following values:Ī string which is used for the replacement. In general, it replaces all (or the first n) occurrences of pat in str with the replacement rep. String.gsub(str, pat, rep, n) is a very powerful string-replacement function which hides considerably more power than its simple syntax would lead you to believe. String.lower(str) and string.upper(str) convert the string to lower and uppercase, respectively. String.len(str) returns the length of the string. ![]() It additionally supports a new format character %q, which formats a string value in a way that can be read back by Lua, escaping or quoting characters as needed (for example quotes, newlines, etc.). String.format(formatstring, …) formats a sequence of values according to the given format string, following the same formatting rules as the ISO C sprintf() function. > for cap in string.gmatch ( a, "%w+" ) do print ( cap ) end Hammerspoon is awesome For example, the following two are equivalent: All of these functions can be called either as regular functions, with the string as the first argument, or as method calls on the string itself, using the colon syntax (which, as we saw before, gets converted to the same call). Lua includes the string library to implement common string manipulation functions, including pattern matching. Patterns, just like regular expressions, are commonly used for string manipulation, using primarily functions from the string library. Unfortunately these are not included in Lua, so you would need to install them on your own. If you encounter something that really cannot be done, you can always resort to libraries like Lrexlib, which provide interfaces to real regex libraries. ![]() For example %d for digits, %s for spaces, %w for alphanumeric characters.įor most common use cases, Lua patterns are enough, you just have to be aware of their differences. Most character classes are represented by the same characters, but preceded by ampersand. The escape character is the ampersand ( %) instead of the backslash ( \). match the shortest possible string instead of the longest one) of the previous character, unlike in regexes, in which it’s commonly indicate by a question mark following the corresponding * or + The regex. The dash ( -) represents a non-greedy “zero or more” (i.e. The caret ( ^) and dollar sign ( $) represent “beginning of string” and “end of string”, just like in regexes. Unlike regexes, these characters can only be applied to a single character and not to a whole capture group (i.e. the regex (foo)+ is not possible).Īlternations, represented by the vertical bar ( |) in regexes, are not supported. The asterisk ( *), plus sign ( +) and question mark ( ?) represent “zero or more”, “one or more” and “one or none” of the previous character, just like in regexes. ) represents any character, just like in regexes. The following are some differences and similarities you need to be aware of when using patterns: They are used by many functions in the string library like string.find() and string.match(). Lua has patterns, which fulfill many of the same functions but have a different syntax and some limitations. If you are familiar with regular expressions, you know how powerful they are for examining and manipulating strings in any programming language. hs.distributednotifications), this technique can be useful. This is a matter of taste-I usually prefer to have the full descriptive names (makes the code easier to read), but when dealing with some of the longer module names (e.g. This avoids the console message and has the additional benefit of allowing you to use app (you can use whatever variable you want) instead of typing hs.application in your code. Gives you some numpad functionality and no chance of freeze up but still nowhere near ideal.> app = require ( 'hs.application' ) > app.get ( "Terminal" ) hs.application : Terminal ( 0圆10000e49118 ) In terms of DIP switches, using SW3 to disable the numlock just helps you avoid pressing it by accident and getting that key press freeze, for the record that's the best workaround I have found. Here is the same output in Karabiner's event viewer:ĮventType:KeyDown code:0x53 name:keypad_1 flags:NumPad misc:ĮventType:KeyUp code:0x53 name:keypad_1 flags:NumPad misc:ĮventType:KeyDown code:0x54 name:keypad_2 flags:NumPad misc:ĮventType:KeyUp code:0x54 name:keypad_2 flags:NumPad misc:ĮventType:KeyDown code:0x47 name:keypad_num_lock flags:Fn misc:ĮventType:KeyUp code:0x47 name:keypad_num_lock flags:Fn misc: (got this last out put by unplugging the numpad, only way to stop the key press) ![]() Gave the program a try, numlock doesn't seem to register at all and after pushing numlock for the second time I land up in that key down freeze I mentioned so no further keys after that. (I feel your pain, I avoided upgrading my OS for fear of Karabiner not working.) If I could se what you get I might be able to help.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |