[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: luasocket wishes (simple).
- From: "Dirk Zoller" <duz@...>
- Date: Tue, 19 Aug 2003 10:49:05 +0200 (CEST)
I'm just migrating our software to Lua-5.0 and also used your
I would like to suggest a few extensions to the C-API of luasocket.
So far the only C-function available seems to be the initialization
method to bring luasocket into a lua_State, i.e. luaopen_socket().
Now, our application is a bit more complex and we want to continue
running our own mainloop even when there are a few extensions
involved, which are written in Lua, also using a socket. Therefore,
besides being able to drag the luasocket library into an interpreter,
we'd like to do the following things:
- Install hook functions which are called whenever a socket is
created or closed, like:
typedef void (*lua_socket_handler_t) (lua_State *, t_sock);
extern lua_socket_handler_t lua_socket_created;
extern lua_socket_handler_t lua_socket_deleted;
BTW, t_sock is int, even in Windows, where it is declared HANDLE,
it is still int., therefore rather:
typedef void (*lua_socket_handler_t) (lua_State *, int socket);
The lua_socket_created hook, unless NULL, is called when a socket is
bound and listen()s, auccessfully connect()ed, or accept()ed a
connection. The lua_socket_deleted hook, unless NULL, is called when
a socket is close()d.
- A C-function to detect if at a specific stack index there is a socket.
You have those internally, but I'd need to use them too.
- Access the socket descriptor inside such a userdata object at a
specific position in the stack.
- A C-function to push a socket userdata object, when I have an "int fd".
With Lua-4.x these things were very easy to patch.
But now, in the wonderful world of "full" userdata items and
metatables, there are too many intricacies. It is no more a
three-liner to achieve the above.
What do you think? Could you publish these hooks and functions?