mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-10-17 02:37:12 +00:00
expose main-loop file descriptor hooks
This commit is contained in:
@@ -304,6 +304,28 @@ def _on_timer_hook(userdata):
|
||||
return 0
|
||||
|
||||
|
||||
@ffi.def_extern()
|
||||
def _on_fd_hook(fd, flags, userdata):
|
||||
hook = ffi.from_handle(userdata)
|
||||
keep = False
|
||||
try:
|
||||
keep = bool(hook.callback(fd, flags, hook.userdata))
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
if not keep:
|
||||
# The C watch removes itself on return; do not unhook it a second time.
|
||||
try:
|
||||
hook.is_unload = True
|
||||
# from_handle() yields a weak proxy: id(proxy) is not id(Hook).
|
||||
for existing in hook.plugin.hooks:
|
||||
if existing == hook:
|
||||
hook.plugin.remove_hook(id(existing))
|
||||
break
|
||||
except ReferenceError:
|
||||
pass # the callback already unhooked itself
|
||||
return int(keep)
|
||||
|
||||
|
||||
@ffi.def_extern()
|
||||
def _on_say_command(word, word_eol, userdata):
|
||||
"""Handle input in the special >>python<< tab.
|
||||
|
||||
Reference in New Issue
Block a user