dbd/sqlite3/connection.c

changeset 32
03ed0ca09837
parent 22
fd78e9cdc6e9
child 41
e490414a391d
equal deleted inserted replaced
31:999ef93f0dbc 32:03ed0ca09837
194 static int connection_gc(lua_State *L) { 194 static int connection_gc(lua_State *L) {
195 /* always close the connection */ 195 /* always close the connection */
196 connection_close(L); 196 connection_close(L);
197 197
198 return 0; 198 return 0;
199 }
200
201 /*
202 * __tostring
203 */
204 static int connection_tostring(lua_State *L) {
205 connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_SQLITE_CONNECTION);
206
207 lua_pushfstring(L, "%s: %p", DBD_SQLITE_CONNECTION, conn);
208
209 return 1;
199 } 210 }
200 211
201 int dbd_sqlite3_connection(lua_State *L) { 212 int dbd_sqlite3_connection(lua_State *L) {
202 /* 213 /*
203 * instance methods 214 * instance methods
227 lua_setfield(L, -2, "__index"); 238 lua_setfield(L, -2, "__index");
228 239
229 lua_pushcfunction(L, connection_gc); 240 lua_pushcfunction(L, connection_gc);
230 lua_setfield(L, -2, "__gc"); 241 lua_setfield(L, -2, "__gc");
231 242
243 lua_pushcfunction(L, connection_tostring);
244 lua_setfield(L, -2, "__tostring");
245
232 luaL_register(L, DBD_SQLITE_CONNECTION, connection_class_methods); 246 luaL_register(L, DBD_SQLITE_CONNECTION, connection_class_methods);
233 247
234 return 1; 248 return 1;
235 } 249 }

mercurial