luvit/luvit — pull request #237 by philips (2012-06-06 17:20:25+00:00)
Title: Add callback state saver

In fs and stream we need to ensure two pieces of data are not GCd while
I/O is happening: any I/O state data (buffers at this point) and the
callback that will happen after the I/O is complete.

I added a new API and a struct to hold on to this data. rcb is a
reference to the callback placed into LUA_REGISTRYINDEX and rdata is a
table in LUA_REGISTRYINDEX that any number of state variables can be
pushed onto.

This is the API:

typedef struct {
int rcb; /* callback ref */
int rdata; /* string ref */
} luv_cb_state_t;

void luv_callback_state_init(luv_cb_state_t *cbs);
void luv_callback_state_add(lua_State* L, luv_cb_state_t *cbs, int
ndex);
void luv_callback_state_callback_add(lua_State* L, luv_cb_state_t *cbs,
nt index);
void luv_callback_state_callback_rawgeti(lua_State *L, luv_cb_state_t
cbs);
void luv_callback_state_unref(lua_State* L, luv_cb_state_t *cbs);

This first patch introduces the API and converts luv_fs. The second patch fixes #228