src/buffer_event.c

changeset 42
b1742e841e5a
parent 41
fce1995f0db8
child 53
e5ede009d0c5
equal deleted inserted replaced
41:fce1995f0db8 42:b1742e841e5a
1 /* LuaEvent - Copyright (C) 2007 Thomas Harning <harningt@gmail.com> 1 /* LuaEvent - Copyright (C) 2007 Thomas Harning <harningt@gmail.com>
2 * Licensed as LGPL - See doc/COPYING for details */ 2 * Licensed as LGPL - See doc/COPYING for details */
3
4 #include "buffer_event.h" 3 #include "buffer_event.h"
5 #include "luaevent.h" 4 #include "luaevent.h"
6 #include "utility.h" 5 #include "utility.h"
7 #include <lauxlib.h> 6 #include <lauxlib.h>
8 #include <malloc.h> 7 #include <malloc.h>
83 lua_rawseti(L, -2, 1); // Read 82 lua_rawseti(L, -2, 1); // Read
84 lua_pushvalue(L, 4); 83 lua_pushvalue(L, 4);
85 lua_rawseti(L, -2, 2); // Write 84 lua_rawseti(L, -2, 2); // Write
86 lua_pushvalue(L, 5); 85 lua_pushvalue(L, 5);
87 lua_rawseti(L, -2, 3); // Err 86 lua_rawseti(L, -2, 3); // Err
88 87
89 event_buffer_push(L, ev->ev->input); 88 event_buffer_push(L, ev->ev->input);
90 lua_rawseti(L, -2, 4); 89 lua_rawseti(L, -2, 4);
91 event_buffer_push(L, ev->ev->output); 90 event_buffer_push(L, ev->ev->output);
92 lua_rawseti(L, -2, 5); 91 lua_rawseti(L, -2, 5);
93 lua_setfenv(L, -2); 92 lua_setfenv(L, -2);
102 le_bufferevent* ev = buffer_event_get(L, 1); 101 le_bufferevent* ev = buffer_event_get(L, 1);
103 if(ev->ev) { 102 if(ev->ev) {
104 le_buffer *read, *write; 103 le_buffer *read, *write;
105 bufferevent_free(ev->ev); 104 bufferevent_free(ev->ev);
106 ev->ev = NULL; 105 ev->ev = NULL;
107 /* Also clear out the associated input/output event_buffers 106 /* Also clear out the associated input/output event_buffers
108 * since they would have already been freed.. */ 107 * since they would have already been freed.. */
109 lua_getfenv(L, 1); 108 lua_getfenv(L, 1);
110 lua_rawgeti(L, -1, 4); 109 lua_rawgeti(L, -1, 4);
111 lua_rawgeti(L, -2, 5); 110 lua_rawgeti(L, -2, 5);
112 read = event_buffer_check(L, -2); 111 read = event_buffer_check(L, -2);
133 lua_setfield(L, -2, "__gc"); 132 lua_setfield(L, -2, "__gc");
134 lua_newtable(L); 133 lua_newtable(L);
135 luaL_register(L, NULL, buffer_event_funcs); 134 luaL_register(L, NULL, buffer_event_funcs);
136 lua_setfield(L, -2, "__index"); 135 lua_setfield(L, -2, "__index");
137 lua_pop(L, 1); 136 lua_pop(L, 1);
138 137
139 luaL_register(L, "luaevent.core.bufferevent", funcs); 138 luaL_register(L, "luaevent.core.bufferevent", funcs);
140 return 1; 139 return 1;
141 } 140 }

mercurial