Simon Slavin wrote on Sunday, October 25, 2015 6:59 AM > On 25 Oct 2015, at 10:05am, Lev <leventelist at gmail.com> wrote: > > > Untill now my architecture does all the SQLite work in C, and pass > > simple variables on Lua's stack. > > > > Today morning I've got an idea to push only the database connection > object. > > The database is opened in the C code, however I only have a single > > thread, so no other entity is accessing the database at the same time. > > Can you use LuaSQLite3 or Lua-Sqlite3 to open a connection initially ? > > <http://lua.sqlite.org/index.cgi/index> > <http://www.mroth.net/lua-sqlite3/> > > > Other solution would be to pass the filename of the database, but > then > > I have to close the connection. Must I? > > You can have a C connection and a Lua connection at the same time, as > long as you don't need to perform operations in both at the same time. >
I've had good luck compiling in lsqlite3, then registering the sqlite db handle into the Lua context using code like this LuaIntf::LuaContext lua_context; lua_context.importLibs(); sqlite3* db_handle = open_db_somehow(); if(1 == luaopen_lsqlite3(lua_context.state())) LuaIntf::Lua::popToGlobal(lua_context.state(), "sqlite3"); else throw runtime_error("error adding lsqlite3 to Lua context"); if(1 == lsqlite_do_open(lua_context.state(), NULL, db_handle)) LuaIntf::Lua::popToGlobal(lua_context.state(), "db_name"); else throw runtime_error("error adding database to Lua context"); This example is using the excellent lua-intf library by Steve K. Chiu https://github.com/SteveKChiu/lua-intf ---------------------------------------------------------------------- This message, and any attachments, is for the intended recipient(s) only, may contain information that is privileged, confidential and/or proprietary and subject to important terms and conditions available at http://www.bankofamerica.com/emaildisclaimer. If you are not the intended recipient, please delete this message.