diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-07-15 06:11:53 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-07-15 06:11:53 +0000 |
| commit | 9a79d500eb3e015f5bf579aab714916d49c1f289 (patch) | |
| tree | db658e87a17e5417ec01ab4a1b0249bdaf2bd1d2 /src/io.c | |
| parent | 471334c3d07f398e4b0859c43276341a28b91504 (diff) | |
| download | luasocket-9a79d500eb3e015f5bf579aab714916d49c1f289.tar.gz luasocket-9a79d500eb3e015f5bf579aab714916d49c1f289.tar.bz2 luasocket-9a79d500eb3e015f5bf579aab714916d49c1f289.zip | |
Still need to fix windows. :o/
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 | } | ||
