Comments (13)
from hammerspoon.
I found how to solve this issue using rawset
function declare (name, initval)
rawset(_G, name, initval or false)
end
counter, offset = 0, 1
declare("counter", 0)
declare("offset", 1)
from hammerspoon.
It works fine on my Hammerspoon. Do you have any code in your config (or loaded Spoons) that would be setting a metatable on the global environment?
What does this code print for you when pasted into the console?
local mt = getmetatable(_G)
if mt then
print(hs.inspect(mt))
for k,v in pairs(mt) do
if type(v) == 'function' then
local info = debug.getinfo(v)
if what ~= 'C' then
print(hs.inspect(info))
end
end
end
else
print('no metatable on _G')
end
from hammerspoon.
from hammerspoon.
Weird… When you ran into the issue, was it in the console or the config file? If it was the config, try putting the code I sent there instead of in the console and see if that prints anything different.
Actually, just in case _G
isn't what's getting used for some reason, can you try using this version instead?
local function checkMT(name, tbl)
local mt = getmetatable(tbl)
if mt then
print(hs.inspect(mt))
for k,v in pairs(mt) do
if type(v) == 'function' then
local info = debug.getinfo(v)
if what ~= 'C' then
print(hs.inspect(info))
end
end
end
else
print('no metatable on '..name)
end
end
checkMT('_G', _G)
if rawequal(_ENV, _G) then
print '_ENV is _G'
else
print '_ENV is not _G'
checkMT('_ENV', _ENV)
end
from hammerspoon.
from hammerspoon.
What about when you run it from within your reset
and/or inc
functions? Also, is there anywhere you're declaring counter
and/or offset
as local
s (or function argument names)?
from hammerspoon.
from hammerspoon.
I don't know of anything else that could interfere with setting global variables. As far as I know, Hammerspoon should be using an unmodified Lua interpreter.
The only other thing I can think of to try right now is moving your entire init.lua
file aside and making a new one with just the code from your initial post. If that works correctly, we can try to narrow down exactly where it starts breaking. If it still fails, I'm not sure what to do.
from hammerspoon.
from hammerspoon.
from hammerspoon.
I see a couple of issues in that code that might explain why the counter isn't updating properly:
- I don't see a definition for that
setOffset
function anywhere, and even if it exists, any change it makes tooffset
will get overwritten by theoffset =
part of the menu item'sfn
- changing it to whateversetOffset
's return value was. - This version of
reset
doesn't seem to actually setcounter
at all - it just updates the menu's title and shows the alert. Also, it's settingoffset
toreset
's return value, which isnil
- meaning that any Increase/Decrease commands after that point will throw anattempt to perform arithmetic on a nil value
error and not actually change the counter.
These next two aren't directly related to the counter problem, but:
$
and^
aren't their own keys, at least on most keyboard layouts that I know of, so they don't have keycodes defined inhs.keycodes.map
and can't be passed directly tohs.hotkey.bind
like that. Assuming that they're Shift-4 and Shift-6 like on my keyboard, you'll need to do something like:
hyper = {"cmd","alt","ctrl"}
hyperShift = {"cmd","alt","ctrl","shift"}
hs.hotkey.bind(hyperShift, "4", function()
updateCounter(offset)
end)
hs.hotkey.bind(hyperShift, "6", function()
updateCounter(-offset)
end)
"Set offset (" .. offset .. ")"
: This title will get evaluated once when your config first runs, and won't update when theoffset
is changed. You can either include something like:
menuMenu[4].title = "Set offset (" .. offset .. ")"
menu:setMenu(menuMenu)
in your setOffset
function, or change menuMenu
to a function so it gets re-evaluated each time the menu opens:
function menuMenu()
return {
{ title = "Increase", fn = function() updateCounter(offset) end },
{ title = "Decrease", fn = function() updateCounter(-offset) end },
{ title = "-" },
{ title = "Set offset (" .. offset .. ")" , fn = function() offset = setOffset(offset) end },
{ title = "Reset counter", fn = function() offset = reset() end }
}
end
from hammerspoon.
Glad to hear it's working for you.
Concerning both keys (« $ » and « ^ »), they are direct own keys on a French keyboard!
Gotcha. For some reason I wasn't sure if Hammerspoon knew that, though, but I see now that it does properly update hs.keycodes.map
to include $ and ^ when you're on that layout.
from hammerspoon.
Related Issues (20)
- .
- `hs.wifi` not showing current network in Sonoma 14.2.1 HOT 3
- Opening Spoon's code on macOS removes the code
- hs.execute window opens in background
- Modifier key's single tapping problems.
- Cannot get all windows across all spaces for multi-instance applications (like firefox with profiles)
- Bug: changing brightness via BetterDisplay causes Hammerspoon to get stuck
- spaces.lua's search for Dock does not succeed on early startup HOT 3
- [bug] Hammerspoon (and forked child processes) can't see files in `/Applications` when launched as a Login Item HOT 10
- Hammerspoon crashes upon hs.reload(), and won't successfully execute again until macOS reboot
- Shift agruments in `hotkey.new`
- Is there a solution to implement SpaceFN
- Hammerspoon does not respond/hang when the frontmost application does not respond
- Feature Request: I would like to know if a modal is in the state active HOT 1
- Feature request: `:keydown` callback for `hs.chooser`
- Delete Preferences modal is confusing
- Moving Apps To Spaces HOT 2
- Memory is growing up to 2-4GB after some time - how to debug? HOT 1
- ** Warning: LuaSkin: hs.audiodevice.watcher callback fired, but theWatcher is nil. This is a bug
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hammerspoon.