0

I have C++ with Lua binding. All is OK, but if I add SQLite, my scripts stop working (not even an empty script with just one print runs).

In my C++ code, I call

luaL_openlibs( this->state );
luaopen_lsqlite3(this->state); /* sqlite */

If I do this, Lua script no longer works.

If I remove (comment out) luaopen_lsqlite3, scripts are working (but obviously without SQLite). What is wrong? Or what I need to call?

I am using http://lua.sqlite.org/index.cgi/index

1 Answer 1

1

I have found a solution, that requires to edit Lua source files.


In lualib.h add

#define LUA_SQLLIBNAME  "lsqlite3"
LUAMOD_API int (luaopen_lsqlite3)(lua_State *L);

before

LUALIB_API void (luaL_openlibs) (lua_State *L);

In linit.h add this {LUA_SQLLIBNAME, luaopen_lsqlite3 } to loadedlibs array. You get

static const luaL_Reg loadedlibs[] = {
  {"_G", luaopen_base},
  {LUA_LOADLIBNAME, luaopen_package},
  {LUA_COLIBNAME, luaopen_coroutine},
  {LUA_TABLIBNAME, luaopen_table},
  {LUA_IOLIBNAME, luaopen_io},
  {LUA_OSLIBNAME, luaopen_os},
  {LUA_STRLIBNAME, luaopen_string},
  {LUA_BITLIBNAME, luaopen_bit32},
  {LUA_MATHLIBNAME, luaopen_math},
  {LUA_DBLIBNAME, luaopen_debug},
  {LUA_SQLLIBNAME, luaopen_lsqlite3 },
  {NULL, NULL}
};

Now, If you call luaL_openlibs, SQLite support will be in your code after calling local sqlite3 = require("lsqlite3") in Lua

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.