dbd/db2/connection.c

changeset 32
03ed0ca09837
parent 26
cf847efefdb5
equal deleted inserted replaced
31:999ef93f0dbc 32:03ed0ca09837
228 connection_close(L); 228 connection_close(L);
229 229
230 return 0; 230 return 0;
231 } 231 }
232 232
233 /*
234 * __tostring
235 */
236 static int connection_tostring(lua_State *L) {
237 connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_DB2_CONNECTION);
238
239 lua_pushfstring(L, "%s: %p", DBD_DB2_CONNECTION, conn);
240
241 return 1;
242 }
243
233 int dbd_db2_connection(lua_State *L) { 244 int dbd_db2_connection(lua_State *L) {
234 static const luaL_Reg connection_methods[] = { 245 static const luaL_Reg connection_methods[] = {
235 {"autocommit", connection_autocommit}, 246 {"autocommit", connection_autocommit},
236 {"close", connection_close}, 247 {"close", connection_close},
237 {"commit", connection_commit}, 248 {"commit", connection_commit},
253 lua_setfield(L, -2, "__index"); 264 lua_setfield(L, -2, "__index");
254 265
255 lua_pushcfunction(L, connection_gc); 266 lua_pushcfunction(L, connection_gc);
256 lua_setfield(L, -2, "__gc"); 267 lua_setfield(L, -2, "__gc");
257 268
269 lua_pushcfunction(L, connection_tostring);
270 lua_setfield(L, -2, "__tostring");
271
258 luaL_register(L, DBD_DB2_CONNECTION, connection_class_methods); 272 luaL_register(L, DBD_DB2_CONNECTION, connection_class_methods);
259 273
260 return 1; 274 return 1;
261 } 275 }

mercurial