340 statement_close(L); |
340 statement_close(L); |
341 |
341 |
342 return 0; |
342 return 0; |
343 } |
343 } |
344 |
344 |
|
345 /* |
|
346 * __tostring |
|
347 */ |
|
348 static int statement_tostring(lua_State *L) { |
|
349 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_SQLITE_STATEMENT); |
|
350 |
|
351 lua_pushfstring(L, "%s: %p", DBD_SQLITE_STATEMENT, statement); |
|
352 |
|
353 return 1; |
|
354 } |
|
355 |
345 int dbd_sqlite3_statement_create(lua_State *L, connection_t *conn, const char *sql_query) { |
356 int dbd_sqlite3_statement_create(lua_State *L, connection_t *conn, const char *sql_query) { |
346 statement_t *statement = NULL; |
357 statement_t *statement = NULL; |
347 |
358 |
348 statement = (statement_t *)lua_newuserdata(L, sizeof(statement_t)); |
359 statement = (statement_t *)lua_newuserdata(L, sizeof(statement_t)); |
349 statement->sqlite = conn->sqlite; |
360 statement->sqlite = conn->sqlite; |
384 lua_setfield(L, -2, "__index"); |
395 lua_setfield(L, -2, "__index"); |
385 |
396 |
386 lua_pushcfunction(L, statement_gc); |
397 lua_pushcfunction(L, statement_gc); |
387 lua_setfield(L, -2, "__gc"); |
398 lua_setfield(L, -2, "__gc"); |
388 |
399 |
|
400 lua_pushcfunction(L, statement_tostring); |
|
401 lua_setfield(L, -2, "__tostring"); |
|
402 |
389 luaL_register(L, DBD_SQLITE_STATEMENT, statement_class_methods); |
403 luaL_register(L, DBD_SQLITE_STATEMENT, statement_class_methods); |
390 |
404 |
391 return 1; |
405 return 1; |
392 } |
406 } |