diff options
Diffstat (limited to 'src/io.c')
-rw-r--r-- | src/io.c | 24 |
1 files changed, 6 insertions, 18 deletions
@@ -12,34 +12,22 @@ | |||
12 | /*-------------------------------------------------------------------------*\ | 12 | /*-------------------------------------------------------------------------*\ |
13 | * Initializes C structure | 13 | * Initializes C structure |
14 | \*-------------------------------------------------------------------------*/ | 14 | \*-------------------------------------------------------------------------*/ |
15 | void io_init(p_io io, p_send send, p_recv recv, p_geterr geterr, void *ctx) { | 15 | void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) { |
16 | io->send = send; | 16 | io->send = send; |
17 | io->recv = recv; | 17 | io->recv = recv; |
18 | io->geterr = geterr; | 18 | io->error = error; |
19 | io->ctx = ctx; | 19 | io->ctx = ctx; |
20 | } | 20 | } |
21 | 21 | ||
22 | /*-------------------------------------------------------------------------*\ | 22 | /*-------------------------------------------------------------------------*\ |
23 | * Translate error codes to Lua | 23 | * I/O error strings |
24 | \*-------------------------------------------------------------------------*/ | 24 | \*-------------------------------------------------------------------------*/ |
25 | const char *io_strerror(int code) { | 25 | const char *io_strerror(int err) { |
26 | switch (code) { | 26 | switch (err) { |
27 | case IO_DONE: return NULL; | 27 | case IO_DONE: return NULL; |
28 | case IO_CLOSED: return "closed"; | 28 | case IO_CLOSED: return "closed"; |
29 | case IO_TIMEOUT: return "timeout"; | 29 | case IO_TIMEOUT: return "timeout"; |
30 | case IO_CLIPPED: return "clipped"; | 30 | case IO_CLIPPED: return "clipped"; |
31 | default: return "unknown error"; | 31 | default: return "unknown error"; |
32 | } | 32 | } |
33 | } | 33 | } |
34 | |||
35 | /*-------------------------------------------------------------------------*\ | ||
36 | * Push error message from code or from driver | ||
37 | \*-------------------------------------------------------------------------*/ | ||
38 | void io_pusherror(lua_State *L, p_io io, int code) | ||
39 | { | ||
40 | const char *err = NULL; | ||
41 | if (code < IO_USER) err = io_strerror(code); | ||
42 | else err = io->geterr(io->ctx, code); | ||
43 | if (err) lua_pushstring(L, err); | ||
44 | else lua_pushnil(L); | ||
45 | } | ||