-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Dynamic timers support #1424
Dynamic timers support #1424
Conversation
Great, I'll have a look. |
@@ -135,20 +141,32 @@ static int tmr_now(lua_State* L){ | |||
return 1; | |||
} | |||
|
|||
// Lua: tmr.register( id, interval, mode, function ) | |||
static int tmr_get( lua_State *L, int stack, timer_t *tmr ) { | |||
if (lua_isuserdata(L, stack)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code can emit a clearer error message if you query the element type first and then have luaL_argcheck()
report a wrong type with something like "timer object or numerical ID expected".
tim = tmr.create()
tim:register(5000, tmr.ALARM_SINGLE, function(t)
print("timer expired")
print(t:state())
t:unregister()
end)
tim:start()
print(tim:state())
-- PANIC when object is destroyed before timer expired
tim = nil Edit: No, it doesn't. My bad. |
} else { | ||
lua_rawgeti(L, LUA_REGISTRYINDEX, tmr->self_ref); | ||
} | ||
lua_call(L, 1, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please stick to a consistent indentation style.
If unsure, follow the Lua style: 2 space indent + 1TBS + no trailing spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
Thanks @devsaurus for review. I will fix codestyle & logics and push it back today. |
Very much appreciated @djphoenix. It's been just some minor aesthetic things while functionality is great. |
c25b250
to
aedca96
Compare
Fixed all of your comments and began to write docs. |
74b9dfe
to
8e8088e
Compare
All done. Also fixed self-unref if mode was SINGLE or SEMI and timer was not rearmed during callbeck. Now this works OK without leaks: function setTimeout(t, f)
return tmr.create():alarm(t, tmr.ALARM_SINGLE, f)
end
setTimeout(1000, function()
print("TICK!")
end) |
I'm missing the deprecation notes for the old-style functions in code and docs. |
My propose is now only add new functions. We may think about deprecation process in another thread. |
You need to think about deprecating the old/existing stuff whenever you add something new that serves as a replacement. Deprecating doesn't mean removing but adding a note to others indicating that existing functionality will or might be removed in the future. That way we give developers some slack to transition to using the new API. Also, we remove reluctance as an obstacle to actually removing old API. |
Ohm. OK. Can you point me to example/instruction of deprecation notes? So I'll do it some later cause AFK. |
We have no guidelines for that, sorry. In essence the word "deprecated" in code and docs is all it takes e.g. http://nodemcu.readthedocs.io/en/latest/en/modules/node/#nodekey-deprecated. |
@marcelstoer check it... And we really need guidelines to deprecation process, both for arguments or functions or whole modules. |
👍 from my side. |
@djphoenix how long will it take till http://nodemcu.readthedocs.io/en/master/en/modules/tmr/ is updated? |
@eku you watching to master-branch docs, they're updating parallel with code at "master drops". Now this feature is only in dev branch, so look for dev docs ;) |
@eku There's a fly-out menu in the lower left corner with which you, amongst others, can select the branch. |
Fixes #1416.
docs/en/*
.I'll write docs soon, now will be great if anyone test this stuff.