int _jason_openlibs(lua_State* L) { luaopen_socket_core(L); /* Opening the Socket library */ luaopen_mime_core(L); /* Opening the Socket library mime support*/ luaopen_lfs(L); /* Opening the Lua Filesystem library */ luaopen_rings(L); /* Opening the Rings library */ luaopen_md5_core(L); /* Opening the MD5 library */ luaopen_base64(L); /* Opening the Base64 library */ luaopen_des56(L); /* Opening the DES56 library */ luaopen_luasystray(L); /* Opening the LuaSysTray library */ luaopen_luamobile(L); /* Opening the LuaMobile library */ /* Opening the LPeg library */ lua_pushcclosure(L, luaopen_lpeg, 0); lua_pushstring(L, "lpeg"); lua_call(L, 1, 0); }
int flexi_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi, FlexiliteContext_t **pDBCtx) { int result; *pDBCtx = (FlexiliteContext_t *) sqlite3_malloc(sizeof(FlexiliteContext_t)); FlexiliteContext_t *pCtx = *pDBCtx; pCtx->db = db; pCtx->L = lua_newstate(lua_alloc_handler, pDBCtx); if (pCtx->L == nullptr) { *pzErrMsg = sqlite3_mprintf("Flexilite: cannot initialize LuaJIT"); result = SQLITE_ERROR; goto ONERROR; } lua_gc(pCtx->L, LUA_GCSTOP, 0); luaL_openlibs(pCtx->L); lua_gc(pCtx->L, LUA_GCRESTART, -1); /* * Open other Lua modules implemented in C */ luaopen_lfs(pCtx->L); luaopen_base64(pCtx->L); luaopen_lsqlite3(pCtx->L); luaopen_cjson(pCtx->L); luaopen_cjson_safe(pCtx->L); // Create context, by passing SQLite db connection if (luaL_dostring(pCtx->L, "return require 'sqlite3'")) { *pzErrMsg = sqlite3_mprintf("Flexilite require sqlite3: %s\n", lua_tostring(pCtx->L, -1)); result = SQLITE_ERROR; goto ONERROR; } lua_getfield(pCtx->L, -1, "open_ptr"); lua_pushlightuserdata(pCtx->L, db); if (lua_pcall(pCtx->L, 1, 1, 0)) { *pzErrMsg = sqlite3_mprintf("Flexilite sqlite.open_ptr: %s\n", lua_tostring(pCtx->L, -1)); result = SQLITE_ERROR; goto ONERROR; } pCtx->SQLiteConn_Index = luaL_ref(pCtx->L, LUA_REGISTRYINDEX); // Create context, by passing SQLite db connection if (luaL_dostring(pCtx->L, "package.cpath = package.cpath .. ';./libFlexilite.dll'; return require ('DBContext')")) { *pzErrMsg = sqlite3_mprintf("Flexilite require DBContext: %s\n", lua_tostring(pCtx->L, -1)); result = SQLITE_ERROR; goto ONERROR; } lua_rawgeti(pCtx->L, LUA_REGISTRYINDEX, pCtx->SQLiteConn_Index); if (lua_pcall(pCtx->L, 1, 1, 0)) { *pzErrMsg = sqlite3_mprintf("Flexilite DBContext(db): %s\n", lua_tostring(pCtx->L, -1)); result = SQLITE_ERROR; goto ONERROR; } pCtx->DBContext_Index = luaL_ref(pCtx->L, LUA_REGISTRYINDEX); result = SQLITE_OK; goto EXIT; ONERROR: flexi_free(pCtx); *pDBCtx = nullptr; EXIT: return result; }