terminate repl & cleanup when eof
This commit is contained in:
parent
6ed0e63a8f
commit
60d4466857
@ -216,20 +216,21 @@ kiwmi_server_event_loop_fd_handler(int fd, uint32_t mask, void *data)
|
|||||||
lua_State *L = lc->server->lua->L;
|
lua_State *L = lc->server->lua->L;
|
||||||
|
|
||||||
lua_rawgeti(L, LUA_REGISTRYINDEX, lc->callback_ref);
|
lua_rawgeti(L, LUA_REGISTRYINDEX, lc->callback_ref);
|
||||||
lua_pushvalue(L, -1);
|
|
||||||
lua_pushinteger(L, fd);
|
lua_pushinteger(L, fd);
|
||||||
lua_pushinteger(L, mask);
|
lua_pushinteger(L, mask);
|
||||||
|
|
||||||
if (lua_pcall(L, 2, 0, 0)) {
|
if (lua_pcall(L, 2, 1, 0)) {
|
||||||
wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1));
|
wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1));
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
FIXME we need to call
|
/* if callback returns false/nil, remove the handler */
|
||||||
|
if (! lua_toboolean(L, -1)) {
|
||||||
|
wl_event_source_remove(lc->event_source);
|
||||||
|
|
||||||
luaL_unref(L, LUA_REGISTRYINDEX, lc->callback_ref);
|
luaL_unref(L, LUA_REGISTRYINDEX, lc->callback_ref);
|
||||||
free(lc);
|
free(lc);
|
||||||
|
}
|
||||||
when the file is closed, but probably not before then
|
lua_pop(L, -1);
|
||||||
*/
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,7 +243,6 @@ l_kiwmi_server_event_loop_add_fd(lua_State *L)
|
|||||||
|
|
||||||
struct kiwmi_server *server = obj->object;
|
struct kiwmi_server *server = obj->object;
|
||||||
|
|
||||||
|
|
||||||
int fd = lua_tonumber(L, 2);
|
int fd = lua_tonumber(L, 2);
|
||||||
int mode = lua_tonumber(L, 3);
|
int mode = lua_tonumber(L, 3);
|
||||||
luaL_checktype(L, 4, LUA_TFUNCTION); // callback
|
luaL_checktype(L, 4, LUA_TFUNCTION); // callback
|
||||||
@ -265,12 +265,14 @@ l_kiwmi_server_event_loop_add_fd(lua_State *L)
|
|||||||
/* luaL_ref pops last parameter (callback) from stack */
|
/* luaL_ref pops last parameter (callback) from stack */
|
||||||
lc->callback_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
lc->callback_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
|
|
||||||
wl_event_loop_add_fd(server->wl_event_loop,
|
lc->event_source =
|
||||||
fd,
|
wl_event_loop_add_fd(server->wl_event_loop,
|
||||||
event_types,
|
fd,
|
||||||
kiwmi_server_event_loop_fd_handler,
|
event_types,
|
||||||
lc);
|
kiwmi_server_event_loop_fd_handler,
|
||||||
return true;
|
lc);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,6 +40,9 @@ whenever there is activity on the file descriptor `fd`. The `mode` parameter
|
|||||||
is one of `O_RDWR`, `O_RDONLY`, `O_WRONLY` as defined in luaposix
|
is one of `O_RDWR`, `O_RDONLY`, `O_WRONLY` as defined in luaposix
|
||||||
`posix.fcntl` module.
|
`posix.fcntl` module.
|
||||||
|
|
||||||
|
If `callback` returns false or nil, the handler will be unregistered
|
||||||
|
from the event loop and not called again.
|
||||||
|
|
||||||
#### kiwmi:focused_view()
|
#### kiwmi:focused_view()
|
||||||
|
|
||||||
Returns the currently focused view.
|
Returns the currently focused view.
|
||||||
|
@ -21,16 +21,28 @@
|
|||||||
))
|
))
|
||||||
|
|
||||||
(fn start [pathname]
|
(fn start [pathname]
|
||||||
(print pathname)
|
|
||||||
(unistd.unlink pathname)
|
(unistd.unlink pathname)
|
||||||
(unix-socket-listener
|
(unix-socket-listener
|
||||||
pathname
|
pathname
|
||||||
(fn [fd]
|
(fn [fd]
|
||||||
(let [sock (fdopen fd "w+")
|
(let [sock (fdopen fd "w+")
|
||||||
repl-coro (coroutine.create repl)]
|
repl-coro (coroutine.create repl)]
|
||||||
(print :fd fd :sock sock)
|
|
||||||
(watch-fd fd fcntl.O_RDONLY
|
(watch-fd fd fcntl.O_RDONLY
|
||||||
#(coroutine.resume repl-coro (unistd.read $1 1024)))
|
(fn [fd]
|
||||||
|
(let [buf (unistd.read fd 1024)
|
||||||
|
input
|
||||||
|
(if (and buf (> (# buf) 0))
|
||||||
|
buf
|
||||||
|
"\n,exit")]
|
||||||
|
(coroutine.resume repl-coro input))
|
||||||
|
(if (= (coroutine.status repl-coro) :dead)
|
||||||
|
(do
|
||||||
|
(sock:write "bye!\n")
|
||||||
|
(sock:close)
|
||||||
|
(unistd.close fd)
|
||||||
|
false)
|
||||||
|
true
|
||||||
|
)))
|
||||||
(coroutine.resume repl-coro
|
(coroutine.resume repl-coro
|
||||||
{:readChunk
|
{:readChunk
|
||||||
(fn [{: stack-size}]
|
(fn [{: stack-size}]
|
||||||
|
Loading…
Reference in New Issue
Block a user