void cLuaState::RegisterAPILibs(void) { tolua_AllToLua_open(m_LuaState); cManualBindings::Bind(m_LuaState); DeprecatedBindings::Bind(m_LuaState); luaopen_lsqlite3(m_LuaState); luaopen_lxp(m_LuaState); }
static void prepare_lua_environment(struct mg_connection *conn, lua_State *L) { const struct mg_request_info *ri = &conn->request_info; extern void luaL_openlibs(lua_State *); int i; luaL_openlibs(L); #ifdef USE_LUA_SQLITE3 { extern int luaopen_lsqlite3(lua_State *); luaopen_lsqlite3(L); } #endif luaL_newmetatable(L, LUASOCKET); lua_pushliteral(L, "__index"); luaL_newlib(L, luasocket_methods); lua_rawset(L, -3); lua_pop(L, 1); lua_register(L, "connect", lsp_connect); if (conn == NULL) return; // Register mg module lua_newtable(L); reg_function(L, "read", lsp_read, conn); reg_function(L, "write", lsp_write, conn); reg_function(L, "cry", lsp_cry, conn); reg_function(L, "include", lsp_include, conn); reg_function(L, "redirect", lsp_redirect, conn); reg_string(L, "version", MONGOOSE_VERSION); // Export request_info lua_pushstring(L, "request_info"); lua_newtable(L); reg_string(L, "request_method", ri->request_method); reg_string(L, "uri", ri->uri); reg_string(L, "http_version", ri->http_version); reg_string(L, "query_string", ri->query_string); reg_int(L, "remote_ip", ri->remote_ip); reg_int(L, "remote_port", ri->remote_port); reg_int(L, "num_headers", ri->num_headers); lua_pushstring(L, "http_headers"); lua_newtable(L); for (i = 0; i < ri->num_headers; i++) { reg_string(L, ri->http_headers[i].name, ri->http_headers[i].value); } lua_rawset(L, -3); lua_rawset(L, -3); lua_setglobal(L, "mg"); // Register default mg.onerror function luaL_dostring(L, "mg.onerror = function(e) mg.write('\\nLua error:\\n', " "debug.traceback(e, 1)) end"); }
void Context::bind(int argc, char **argv) { DOM::luaBinding (lua); DSRE::luaBinding(lua); WebDriver::luaBinding(lua); luaopen_lsqlite3(lua.lua_state()); lua_setglobal(lua.lua_state(), "sqlite3"); lua.create_named_table("args"); for (int i = 0; i < argc; ++i) { lua["args"][i + 1] = std::string(argv[i]); } }
void cLuaState::Create(void) { if (m_LuaState != NULL) { LOGWARNING("%s: Trying to create an already-existing LuaState, ignoring.", __FUNCTION__); return; } m_LuaState = lua_open(); luaL_openlibs(m_LuaState); tolua_AllToLua_open(m_LuaState); ManualBindings::Bind(m_LuaState); luaopen_lsqlite3(m_LuaState); luaopen_lxp(m_LuaState); m_IsOwned = true; }
static void load_lua_modules() { //lua::module::open_net(L); lua::module::open_net2(L); lua::module::open_timer(L); lua::module::open_crypto(L); lua::module::open_cubescript(L); lua::module::open_geoip(L); lua::module::open_filesystem(L); lua::module::open_http_server(L); lua_packlibopen(L); #ifdef HAS_LSQLITE3 luaopen_lsqlite3(L); lua_pop(L, 1); #endif }
lua_engine::lua_engine() { m_machine = NULL; luaThis = this; m_lua_state = luaL_newstate(); /* create state */ output_notifier_set = false; luaL_checkversion(m_lua_state); lua_gc(m_lua_state, LUA_GCSTOP, 0); /* stop collector during initialization */ luaL_openlibs(m_lua_state); /* open libraries */ luaopen_lsqlite3(m_lua_state); luaopen_ioport(m_lua_state); lua_gc(m_lua_state, LUA_GCRESTART, 0); msg.ready = 0; msg.status = 0; msg.done = 0; lock = osd_lock_alloc(); }
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; }
int instantiate_lsqlite3_global(lua_State* luaState) { return luaopen_lsqlite3(luaState) ; }
bool cPlugin_NewLua::Initialize(void) { cCSLock Lock(m_CriticalSection); if (m_LuaState == NULL) { m_LuaState = lua_open(); luaL_openlibs(m_LuaState); tolua_AllToLua_open(m_LuaState); ManualBindings::Bind(m_LuaState); luaopen_lsqlite3(m_LuaState); luaopen_lxp(m_LuaState); // Inject the identification global variables into the state: lua_pushlightuserdata(m_LuaState, this); lua_setglobal(m_LuaState, LUA_PLUGIN_INSTANCE_VAR_NAME); lua_pushstring(m_LuaState, GetName().c_str()); lua_setglobal(m_LuaState, LUA_PLUGIN_NAME_VAR_NAME); } std::string PluginPath = FILE_IO_PREFIX + GetLocalDirectory() + "/"; // Load all files for this plugin, and execute them AStringList Files = GetDirectoryContents(PluginPath.c_str()); for (AStringList::const_iterator itr = Files.begin(); itr != Files.end(); ++itr) { if (itr->rfind(".lua") == AString::npos) { continue; } AString Path = PluginPath + *itr; int s = luaL_loadfile(m_LuaState, Path.c_str() ); if( report_errors( m_LuaState, s ) ) { LOGERROR("Can't load plugin %s because of an error in file %s", GetLocalDirectory().c_str(), Path.c_str() ); lua_close( m_LuaState ); m_LuaState = 0; return false; } s = lua_pcall(m_LuaState, 0, LUA_MULTRET, 0); if( report_errors( m_LuaState, s ) ) { LOGERROR("Error in plugin %s in file %s", GetLocalDirectory().c_str(), Path.c_str() ); lua_close( m_LuaState ); m_LuaState = 0; return false; } } // for itr - Files[] // Call intialize function if (!PushFunction("Initialize")) { lua_close( m_LuaState ); m_LuaState = 0; return false; } tolua_pushusertype(m_LuaState, this, "cPlugin_NewLua"); if (!CallFunction(1, 1, "Initialize")) { lua_close( m_LuaState ); m_LuaState = 0; return false; } if( !lua_isboolean( m_LuaState, -1 ) ) { LOGWARN("Error in plugin %s Initialize() must return a boolean value!", GetLocalDirectory().c_str() ); lua_close( m_LuaState ); m_LuaState = 0; return false; } bool bSuccess = (tolua_toboolean(m_LuaState, -1, 0) > 0); return bSuccess; }