*** 37,113 **** #include "lua_procedural.h" #endif ! /* ! ** Close an existing SQLite database ! */ ! int sqlite3_close(sqlite3 *db){ HashElem *i; int j; ! #ifdef LUA_SQLITE_PROCEDURAL lua_State *L; ! #endif if( !db ){ return SQLITE_OK; } if( sqlite3SafetyCheck(db) ){ return SQLITE_MISUSE; } ! #ifdef LUA_SQLITE_PROCEDURAL L = (lua_State*) sqlite3_get_db_user_data(db); ! #endif ! ...... ! #ifdef LUA_SQLITE_PROCEDURAL if (L) lua_close(L); ! #endif return SQLITE_OK; ! } ! ..... ! /* ! ** This routine does the work of opening a database on behalf of ! ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename" ! ** is UTF-8 encoded. ! */ ! static int openDatabase( const char *zFilename, /* Database filename UTF-8 encoded */ sqlite3 **ppDb /* OUT: Returned database handle */ ! ){ sqlite3 *db; int rc; CollSeq *pColl; ! ....... ! opendb_out: if( SQLITE_NOMEM==(rc = sqlite3_errcode(db)) ){ sqlite3_close(db); db = 0; } *ppDb = db; ! #ifdef LUA_SQLITE_PROCEDURAL install_lua_procedural(db); ! #endif return sqlite3ApiExit(0, rc); ! } ! void sqlite3_set_db_user_data(sqlite3 *db, void *data){ assert( db ); db->pDBUserData = data; ! } ! void *sqlite3_get_db_user_data(sqlite3 *db){ assert( db ); return db->pDBUserData; ! } ! ---------------------- ! sqlit3Int.h: ! ---------------------- ! struct sqlite3 { int nDb; /* Number of backends currently in use */ ! ......... void *pDBUserData; ! }; ! struct sqlite3_context { FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */ VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */ Mem s; /* The return value is stored here */ --- 37,113 ---- #include "lua_procedural.h" #endif ! /* ! ** Close an existing SQLite database ! */ ! int sqlite3_close(sqlite3 *db){ HashElem *i; int j; ! #ifdef LUA_SQLITE_PROCEDURAL lua_State *L; ! #endif if( !db ){ return SQLITE_OK; } if( sqlite3SafetyCheck(db) ){ return SQLITE_MISUSE; } ! #ifdef LUA_SQLITE_PROCEDURAL L = (lua_State*) sqlite3_get_db_user_data(db); ! #endif ! ...... ! #ifdef LUA_SQLITE_PROCEDURAL if (L) lua_close(L); ! #endif return SQLITE_OK; ! } ! ..... ! /* ! ** This routine does the work of opening a database on behalf of ! ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename" ! ** is UTF-8 encoded. ! */ ! static int openDatabase( const char *zFilename, /* Database filename UTF-8 encoded */ sqlite3 **ppDb /* OUT: Returned database handle */ ! ){ sqlite3 *db; int rc; CollSeq *pColl; ! ....... ! opendb_out: if( SQLITE_NOMEM==(rc = sqlite3_errcode(db)) ){ sqlite3_close(db); db = 0; } *ppDb = db; ! #ifdef LUA_SQLITE_PROCEDURAL install_lua_procedural(db); ! #endif return sqlite3ApiExit(0, rc); ! } ! void sqlite3_set_db_user_data(sqlite3 *db, void *data){ assert( db ); db->pDBUserData = data; ! } ! void *sqlite3_get_db_user_data(sqlite3 *db){ assert( db ); return db->pDBUserData; ! } ! ---------------------- ! sqlit3Int.h: ! ---------------------- ! struct sqlite3 { int nDb; /* Number of backends currently in use */ ! ......... void *pDBUserData; ! }; ! struct sqlite3_context { FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */ VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */ Mem s; /* The return value is stored here */ *************** *** 115,148 **** u8 isError; /* Set to true for an error */ CollSeq *pColl; /* Collating sequence */ void *pDBUserData; ! }; ! ------ ! lua_procedural.h: ! ----------------- ! #ifdef LUA_SQLITE_PROCEDURAL ! //lua includes ! #include "lua.h" ! #include "lauxlib.h" ! extern int luaopen_lsqlite3(lua_State *L); ! extern int lsqlite_register_db(lua_State *L, sqlite3 *db, const char *name); ! ! /* ! Install the main interpreter function ! */ ! static void install_lua_script( sqlite3_context *context, int argc, sqlite3_value **argv ! ){ assert( argc==1 ); lua_State *L = (lua_State*) sqlite3_db_user_data(context); if(L && sqlite3_value_type(argv[0]) == SQLITE_TEXT){ int res = luaL_dostring(L, sqlite3_value_text(argv[0])); sqlite3_result_int(context,res); } else sqlite3_result_null(context); ! } ! static int install_lua_procedural(sqlite3 *db){ lua_State *L = lua_open(); if(L){ luaL_openlibs(L); /* Load Lua libraries */ --- 115,148 ---- u8 isError; /* Set to true for an error */ CollSeq *pColl; /* Collating sequence */ void *pDBUserData; ! }; ! ------ ! lua_procedural.h: ! ----------------- ! #ifdef LUA_SQLITE_PROCEDURAL ! //lua includes ! #include "lua.h" ! #include "lauxlib.h" ! extern int luaopen_lsqlite3(lua_State *L); ! extern int lsqlite_register_db(lua_State *L, sqlite3 *db, const char *name); ! ! /* ! Install the main interpreter function ! */ ! static void install_lua_script( sqlite3_context *context, int argc, sqlite3_value **argv ! ){ assert( argc==1 ); lua_State *L = (lua_State*) sqlite3_db_user_data(context); if(L && sqlite3_value_type(argv[0]) == SQLITE_TEXT){ int res = luaL_dostring(L, sqlite3_value_text(argv[0])); sqlite3_result_int(context,res); } else sqlite3_result_null(context); ! } ! static int install_lua_procedural(sqlite3 *db){ lua_State *L = lua_open(); if(L){ luaL_openlibs(L); /* Load Lua libraries */ *************** *** 157,161 **** //fprintf(stderr,"Unable to register lua scripting engine !\n"); return -1; } ! } ! #endif --- 157,161 ---- //fprintf(stderr,"Unable to register lua scripting engine !\n"); return -1; } ! } ! #endif