Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

问个问题 #23

Closed
nzhl opened this issue Apr 22, 2017 · 5 comments
Closed

问个问题 #23

nzhl opened this issue Apr 22, 2017 · 5 comments

Comments

@nzhl
Copy link

nzhl commented Apr 22, 2017

看了你的hammer配置, 特别受启发, 因为我不是特别懂lua, 我写了一个类似你的时钟的东西, 就是在桌面上实时显示时钟, 但是我在代码中用的是类似(local time = hs.drawing. ... ), 然后动态跟新时钟直接就是 hs.timer.doEvery(...) , 也就是说我没有像你一样将timer保存为一个全局变量, 我不是很清楚lua垃圾回收机制是怎么工作的, 我刚开始直接尝试的时候, 发现是可以. 但是最近发现有时候时钟会莫名其妙的停住(不再刷新, 尝试debug发现我doEvery里面的回调函数已经不再执行了, 本来我设置的是每秒刷新一下, 就达到时间在桌面动态显示的结果) 想问一下这个是lua的gc把我的timer回收导致的吗?

@ashfinal
Copy link
Owner

我也不懂 lua。当时是看完 Learn Lua in Y minutes 就尝试写了,没多学别的什么东西 ……
感觉很多时间都花看 Hammerspoon 文档上了,到现在好像也没出什么大问题。(-ι_- )

以我有限的理解,timer 全局变量与否与 lua 的 gc 回收关系不大。你可以检查下该 timer 是不是还在运行,有没有变量重复命名被覆盖的情况?或者函数本身写的就有问题。

@nzhl
Copy link
Author

nzhl commented Apr 23, 2017

稍微看了下官方文档, 我问题应该是出在timer没有使用变量保存起来, 不过还是非常感谢... 感觉用hammerspoon的人好少啊, 这个东西真的是神器.

@ashfinal
Copy link
Owner

我刚点进你的 repo 看到相关代码了。确实是因为你没有把 hs.timer 对象赋值,没赋值的话这个对象就是“野”的,gc 的时候会被回收掉。

用的人是少了点,上手难度高了些。不过自己感觉有用就成。

@nzhl
Copy link
Author

nzhl commented Apr 23, 2017

多谢了
不过真的 感谢, 我一开只是知道这个软件, 但是后面github上搜索到你的配置, 真是, 我觉得你真的有想法. 我都没想过可以这么弄.

@ashfinal
Copy link
Owner

大概扫一遍 API 文档,就慢慢有了些想法,就想尝试下能不能实现 ……
但是文档其实也没有细看全看,只是知道它们大概能做什么,到写的时候边写边看。

有空多交流交流哈,有想法或代码欢迎 contribute。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants