file: raise error on .on() with non-function/nil
Seems more polite than quietly accepting other types as nil.
This commit is contained in:
parent
31c71c0e5d
commit
a7f8564424
|
@ -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;
|
||||
|
|
|
@ -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`
|
||||
|
|
Loading…
Reference in New Issue