--- lsqlite3-6/lsqlite3.c 2007-08-17 17:42:42.000000000 -0400 +++ lsqlite3-6-new/lsqlite3.c 2008-03-11 12:44:45.000000000 -0400 @@ -648,6 +648,8 @@ static sdb *lsqlite_getdb(lua_State *L, int index) { sdb *db = (sdb*)luaL_checkudata(L, index, sqlite_meta); if (db == NULL) luaL_typerror(L, index, "sqlite database"); + /* Ensure that L is up to date for this sequence */ + db->L = L; return db; } @@ -1097,14 +1099,14 @@ */ typedef struct { - lua_State *L; + sdb *db; int ref; } scc; static int collwrapper(scc *co,int l1,const void *p1, int l2,const void *p2) { int res=0; - lua_State *L=co->L; + lua_State *L=co->db->L; lua_rawgeti(L,LUA_REGISTRYINDEX,co->ref); lua_pushlstring(L,p1,l1); lua_pushlstring(L,p2,l2); @@ -1115,7 +1117,7 @@ static void collfree(scc *co) { if (co) { - luaL_unref(co->L,LUA_REGISTRYINDEX,co->ref); + luaL_unref(co->db->L,LUA_REGISTRYINDEX,co->ref); free(co); } } @@ -1133,7 +1135,7 @@ co=(scc *)malloc(sizeof(scc)); // userdata is a no-no as it // will be garbage-collected if (co) { - co->L=L; + co->db=db; /* lua_settop(L,3) above means we don't need: lua_pushvalue(L,3); */ co->ref=luaL_ref(L,LUA_REGISTRYINDEX); }