diff --git a/app/modules/file.c b/app/modules/file.c index db717076..b5f14292 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -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; diff --git a/docs/modules/file.md b/docs/modules/file.md index 75ecc2ef..4426e979 100644 --- a/docs/modules/file.md +++ b/docs/modules/file.md @@ -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`