/** Initialize the Lua VM * \param xdg An xdg handle to use to get XDG basedir. */ void luaA_init(xdgHandle* xdg) { lua_State *L; static const struct luaL_reg awesome_lib[] = { { "quit", luaA_quit }, { "exec", luaA_exec }, { "spawn", luaA_spawn }, { "restart", luaA_restart }, { "add_signal", luaA_awesome_add_signal }, { "remove_signal", luaA_awesome_remove_signal }, { "emit_signal", luaA_awesome_emit_signal }, { "__index", luaA_awesome_index }, { "__newindex", luaA_awesome_newindex }, { NULL, NULL } }; L = globalconf.L = luaL_newstate(); /* Set panic function */ lua_atpanic(L, luaA_panic); /* Set error handling function */ lualib_dofunction_on_error = luaA_dofunction_on_error; luaL_openlibs(L); luaA_fixups(L); luaA_object_setup(L); /* Export awesome lib */ luaA_openlib(L, "awesome", awesome_lib, awesome_lib); /* Export root lib */ luaL_register(L, "root", awesome_root_lib); lua_pop(L, 1); /* luaL_register() leaves the table on stack */ /* Export hooks lib */ luaL_register(L, "hooks", awesome_hooks_lib); lua_pop(L, 1); /* luaL_register() leaves the table on stack */ #ifdef WITH_DBUS /* Export D-Bus lib */ luaL_register(L, "dbus", awesome_dbus_lib); lua_pop(L, 1); /* luaL_register() leaves the table on stack */ #endif /* Export keygrabber lib */ luaL_register(L, "keygrabber", awesome_keygrabber_lib); lua_pop(L, 1); /* luaL_register() leaves the table on stack */ /* Export mousegrabber lib */ luaL_register(L, "mousegrabber", awesome_mousegrabber_lib); lua_pop(L, 1); /* luaL_register() leaves the table on stack */ /* Export screen */ luaA_openlib(L, "screen", awesome_screen_methods, awesome_screen_meta); /* Export mouse */ luaA_openlib(L, "mouse", awesome_mouse_methods, awesome_mouse_meta); /* Export button */ button_class_setup(L); /* Export image */ image_class_setup(L); /* Export tag */ tag_class_setup(L); /* Export wibox */ wibox_class_setup(L); /* Export widget */ widget_class_setup(L); /* Export client */ client_class_setup(L); /* Export keys */ key_class_setup(L); /* Export timer */ timer_class_setup(L); /* init hooks */ globalconf.hooks.manage = LUA_REFNIL; globalconf.hooks.unmanage = LUA_REFNIL; globalconf.hooks.focus = LUA_REFNIL; globalconf.hooks.unfocus = LUA_REFNIL; globalconf.hooks.mouse_enter = LUA_REFNIL; globalconf.hooks.mouse_leave = LUA_REFNIL; globalconf.hooks.clients = LUA_REFNIL; globalconf.hooks.tags = LUA_REFNIL; globalconf.hooks.tagged = LUA_REFNIL; globalconf.hooks.property = LUA_REFNIL; globalconf.hooks.timer = LUA_REFNIL; globalconf.hooks.exit = LUA_REFNIL; /* add Lua search paths */ lua_getglobal(L, "package"); if (LUA_TTABLE != lua_type(L, 1)) { warn("package is not a table"); return; } lua_getfield(L, 1, "path"); if (LUA_TSTRING != lua_type(L, 2)) { warn("package.path is not a string"); lua_pop(L, 1); return; } /* add XDG_CONFIG_DIR as include path */ const char * const *xdgconfigdirs = xdgSearchableConfigDirectories(xdg); for(; *xdgconfigdirs; xdgconfigdirs++) { size_t len = a_strlen(*xdgconfigdirs); lua_pushliteral(L, ";"); lua_pushlstring(L, *xdgconfigdirs, len); lua_pushliteral(L, "/awesome/?.lua"); lua_concat(L, 3); lua_pushliteral(L, ";"); lua_pushlstring(L, *xdgconfigdirs, len); lua_pushliteral(L, "/awesome/?/init.lua"); lua_concat(L, 3); lua_concat(L, 3); /* concatenate with package.path */ } /* add Lua lib path (/usr/share/awesome/lib by default) */ lua_pushliteral(L, ";" AWESOME_LUA_LIB_PATH "/?.lua"); lua_pushliteral(L, ";" AWESOME_LUA_LIB_PATH "/?/init.lua"); lua_concat(L, 3); /* concatenate with package.path */ lua_setfield(L, 1, "path"); /* package.path = "concatenated string" */ }
/** Initialize the Lua VM * \param xdg An xdg handle to use to get XDG basedir. */ void luaA_init(xdgHandle* xdg) { lua_State *L; static const struct luaL_Reg awesome_lib[] = { { "quit", luaA_quit }, { "exec", luaA_exec }, { "spawn", luaA_spawn }, { "restart", luaA_restart }, { "connect_signal", luaA_awesome_connect_signal }, { "disconnect_signal", luaA_awesome_disconnect_signal }, { "emit_signal", luaA_awesome_emit_signal }, { "systray", luaA_systray }, { "load_image", luaA_load_image }, { "__index", luaA_awesome_index }, { NULL, NULL } }; L = globalconf.L = luaL_newstate(); /* Set panic function */ lua_atpanic(L, luaA_panic); /* Set error handling function */ lualib_dofunction_on_error = luaA_dofunction_on_error; luaL_openlibs(L); luaA_fixups(L); luaA_object_setup(L); /* Export awesome lib */ luaA_openlib(L, "awesome", awesome_lib, awesome_lib); /* Export root lib */ luaA_registerlib(L, "root", awesome_root_lib); lua_pop(L, 1); /* luaA_registerlib() leaves the table on stack */ #ifdef WITH_DBUS /* Export D-Bus lib */ luaA_registerlib(L, "dbus", awesome_dbus_lib); lua_pop(L, 1); /* luaA_registerlib() leaves the table on stack */ #endif /* Export keygrabber lib */ luaA_registerlib(L, "keygrabber", awesome_keygrabber_lib); lua_pop(L, 1); /* luaA_registerlib() leaves the table on stack */ /* Export mousegrabber lib */ luaA_registerlib(L, "mousegrabber", awesome_mousegrabber_lib); lua_pop(L, 1); /* luaA_registerlib() leaves the table on stack */ /* Export screen */ luaA_openlib(L, "screen", awesome_screen_methods, awesome_screen_meta); /* Export mouse */ luaA_openlib(L, "mouse", awesome_mouse_methods, awesome_mouse_meta); /* Export button */ button_class_setup(L); /* Export tag */ tag_class_setup(L); /* Export window */ window_class_setup(L); /* Export drawable */ drawable_class_setup(L); /* Export drawin */ drawin_class_setup(L); /* Export client */ client_class_setup(L); /* Export keys */ key_class_setup(L); /* Export timer */ timer_class_setup(L); /* add Lua search paths */ lua_getglobal(L, "package"); if (LUA_TTABLE != lua_type(L, 1)) { warn("package is not a table"); return; } lua_getfield(L, 1, "path"); if (LUA_TSTRING != lua_type(L, 2)) { warn("package.path is not a string"); lua_pop(L, 1); return; } /* add XDG_CONFIG_DIR as include path */ const char * const *xdgconfigdirs = xdgSearchableConfigDirectories(xdg); for(; *xdgconfigdirs; xdgconfigdirs++) { size_t len = a_strlen(*xdgconfigdirs); lua_pushliteral(L, ";"); lua_pushlstring(L, *xdgconfigdirs, len); lua_pushliteral(L, "/awesome/?.lua"); lua_concat(L, 3); lua_pushliteral(L, ";"); lua_pushlstring(L, *xdgconfigdirs, len); lua_pushliteral(L, "/awesome/?/init.lua"); lua_concat(L, 3); lua_concat(L, 3); /* concatenate with package.path */ } /* add Lua lib path (/usr/share/awesome/lib by default) */ lua_pushliteral(L, ";" AWESOME_LUA_LIB_PATH "/?.lua"); lua_pushliteral(L, ";" AWESOME_LUA_LIB_PATH "/?/init.lua"); lua_concat(L, 3); /* concatenate with package.path */ lua_setfield(L, 1, "path"); /* package.path = "concatenated string" */ lua_getfield(L, 1, "loaded"); lua_pop(L, 2); /* pop "package" and "package.loaded" */ signal_add(&global_signals, "debug::error"); signal_add(&global_signals, "debug::deprecation"); signal_add(&global_signals, "debug::index::miss"); signal_add(&global_signals, "debug::newindex::miss"); signal_add(&global_signals, "systray::update"); signal_add(&global_signals, "wallpaper_changed"); signal_add(&global_signals, "refresh"); signal_add(&global_signals, "exit"); }