2015-08-23 63 views
0

我有C++與Lua綁定。一切正常,但如果我添加SQLite,我的腳本停止工作(即使只運行一個print也不會有空腳本)。C++和Lua與SQLite

在我的C++代碼,我叫

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

如果我這樣做,Lua的腳本不再工作。

如果我刪除(註釋掉)luaopen_lsqlite3,腳本正在工作(但顯然沒有SQLite)。哪裏不對?還是我需要打電話?

我使用http://lua.sqlite.org/index.cgi/index

回答

1

我已經找到了解決辦法,這需要編輯Lua的源文件。


lualib.h添加

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

之前

LUALIB_API void (luaL_openlibs) (lua_State *L); 

linit.h添加此{LUA_SQLLIBNAME, luaopen_lsqlite3 }loadedlibs陣列。你得到

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} 
}; 

現在,如果你打電話luaL_openlibs,SQLite的支持將是你的代碼在Lua調用local sqlite3 = require("lsqlite3")

+0

最好的,發現後。謝謝。 –