Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
a7f85644
Commit
a7f85644
authored
Feb 14, 2020
by
Nathaniel Wesley Filardo
Committed by
Marcel Stör
Jun 09, 2020
Browse files
file: raise error on .on() with non-function/nil
Seems more polite than quietly accepting other types as nil.
parent
31c71c0e
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/modules/file.c
View file @
a7f85644
...
...
@@ -88,15 +88,21 @@ static int file_on(lua_State *L)
case
ON_RTC
:
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
rtc_cb_ref
);
if
((
lua_type
(
L
,
2
)
==
LUA_TFUNCTION
)
||
(
lua_type
(
L
,
2
)
==
LUA_TLIGHTFUNCTION
))
{
switch
(
lua_type
(
L
,
2
))
{
case
LUA_TFUNCTION
:
case
LUA_TLIGHTFUNCTION
:
lua_pushvalue
(
L
,
2
);
// copy argument (func) to the top of stack
rtc_cb_ref
=
luaL_ref
(
L
,
LUA_REGISTRYINDEX
);
vfs_register_rtc_cb
(
file_rtc_cb
);
}
else
{
break
;
case
LUA_TNIL
:
rtc_cb_ref
=
LUA_NOREF
;
vfs_register_rtc_cb
(
NULL
);
break
;
default:
luaL_error
(
L
,
"Callback should be function or nil"
);
}
break
;
default:
break
;
...
...
docs/modules/file.md
View file @
a7f85644
...
...
@@ -222,7 +222,7 @@ Trigger events are:
#### Parameters
-
`event`
string
-
`function()`
callback function. Unregisters the callback if
`function()`
is omitted.
-
`function()`
callback function. Unregisters the callback if
`function()`
is omitted
or
`nil`
.
#### Returns
`nil`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment