awful.mouse: remove useless hooks requirement
[awesome.git] / luaa.c
blobcafab36f841e77cc05c9aca09e875db72aaaf43f
1 /*
2 * luaa.c - Lua configuration management
4 * Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #define _GNU_SOURCE
24 #include <ev.h>
26 #include <lua.h>
27 #include <lauxlib.h>
28 #include <lualib.h>
30 #include <basedir_fs.h>
32 #include "awesome.h"
33 #include "awesome-version-internal.h"
34 #include "ewmh.h"
35 #include "luaa.h"
36 #include "spawn.h"
37 #include "tag.h"
38 #include "client.h"
39 #include "screen.h"
40 #include "event.h"
41 #include "selection.h"
42 #include "window.h"
43 #include "common/xcursor.h"
44 #include "common/buffer.h"
46 #ifdef WITH_DBUS
47 extern const struct luaL_reg awesome_dbus_lib[];
48 #endif
49 extern const struct luaL_reg awesome_hooks_lib[];
50 extern const struct luaL_reg awesome_keygrabber_lib[];
51 extern const struct luaL_reg awesome_mousegrabber_lib[];
52 extern const struct luaL_reg awesome_root_methods[];
53 extern const struct luaL_reg awesome_root_meta[];
54 extern const struct luaL_reg awesome_button_methods[];
55 extern const struct luaL_reg awesome_button_meta[];
56 extern const struct luaL_reg awesome_image_methods[];
57 extern const struct luaL_reg awesome_image_meta[];
58 extern const struct luaL_reg awesome_mouse_methods[];
59 extern const struct luaL_reg awesome_mouse_meta[];
60 extern const struct luaL_reg awesome_screen_methods[];
61 extern const struct luaL_reg awesome_screen_meta[];
62 extern const struct luaL_reg awesome_client_methods[];
63 extern const struct luaL_reg awesome_client_meta[];
64 extern const struct luaL_reg awesome_tag_methods[];
65 extern const struct luaL_reg awesome_tag_meta[];
66 extern const struct luaL_reg awesome_widget_methods[];
67 extern const struct luaL_reg awesome_widget_meta[];
68 extern const struct luaL_reg awesome_wibox_methods[];
69 extern const struct luaL_reg awesome_wibox_meta[];
70 extern const struct luaL_reg awesome_key_methods[];
71 extern const struct luaL_reg awesome_key_meta[];
73 /** Quit awesome.
74 * \param L The Lua VM state.
75 * \return The number of elements pushed on stack.
77 static int
78 luaA_quit(lua_State *L __attribute__ ((unused)))
80 ev_unloop(globalconf.loop, 1);
81 return 0;
84 /** Execute another application, probably a window manager, to replace
85 * awesome.
86 * \param L The Lua VM state.
87 * \return The number of elements pushed on stack.
88 * \luastack
89 * \lparam The command line to execute.
91 static int
92 luaA_exec(lua_State *L)
94 const char *cmd = luaL_checkstring(L, 1);
96 awesome_atexit();
98 a_exec(cmd);
99 return 0;
102 /** Restart awesome.
104 static int
105 luaA_restart(lua_State *L __attribute__ ((unused)))
107 awesome_restart();
108 return 0;
111 /** UTF-8 aware string length computing.
112 * \param L The Lua VM state.
113 * \return The number of elements pushed on stack.
115 static int
116 luaA_mbstrlen(lua_State *L)
118 const char *cmd = luaL_checkstring(L, 1);
119 lua_pushnumber(L, (ssize_t) mbstowcs(NULL, NONULL(cmd), 0));
120 return 1;
123 /** Overload standard Lua next function to use __next key on metatable.
124 * \param L The Lua VM state.
125 * \return The number of elements pushed on stack.
127 static int
128 luaAe_next(lua_State *L)
130 if(luaL_getmetafield(L, 1, "__next"))
132 lua_insert(L, 1);
133 lua_call(L, lua_gettop(L) - 1, LUA_MULTRET);
134 return lua_gettop(L);
137 luaL_checktype(L, 1, LUA_TTABLE);
138 lua_settop(L, 2);
139 if(lua_next(L, 1))
140 return 2;
141 lua_pushnil(L);
142 return 1;
145 /** Overload lua_next() function by using __next metatable field
146 * to get next elements.
147 * \param L The Lua VM stack.
148 * \param idx The index number of elements in stack.
149 * \return 1 if more elements to come, 0 otherwise.
152 luaA_next(lua_State *L, int idx)
154 if(luaL_getmetafield(L, idx, "__next"))
156 /* if idx is relative, reduce it since we got __next */
157 if(idx < 0) idx--;
158 /* copy table and then move key */
159 lua_pushvalue(L, idx);
160 lua_pushvalue(L, -3);
161 lua_remove(L, -4);
162 lua_pcall(L, 2, 2, 0);
163 /* next returned nil, it's the end */
164 if(lua_isnil(L, -1))
166 /* remove nil */
167 lua_pop(L, 2);
168 return 0;
170 return 1;
172 else if(lua_istable(L, idx))
173 return lua_next(L, idx);
174 /* remove the key */
175 lua_pop(L, 1);
176 return 0;
179 /** Generic pairs function.
180 * \param L The Lua VM state.
181 * \return The number of elements pushed on stack.
183 static int
184 luaA_generic_pairs(lua_State *L)
186 lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
187 lua_pushvalue(L, 1); /* state, */
188 lua_pushnil(L); /* and initial value */
189 return 3;
192 /** Overload standard pairs function to use __pairs field of metatables.
193 * \param L The Lua VM state.
194 * \return The number of elements pushed on stack.
196 static int
197 luaAe_pairs(lua_State *L)
199 if(luaL_getmetafield(L, 1, "__pairs"))
201 lua_insert(L, 1);
202 lua_call(L, lua_gettop(L) - 1, LUA_MULTRET);
203 return lua_gettop(L);
206 luaL_checktype(L, 1, LUA_TTABLE);
207 return luaA_generic_pairs(L);
210 static int
211 luaA_ipairs_aux(lua_State *L)
213 int i = luaL_checkint(L, 2) + 1;
214 luaL_checktype(L, 1, LUA_TTABLE);
215 lua_pushinteger(L, i);
216 lua_rawgeti(L, 1, i);
217 return (lua_isnil(L, -1)) ? 0 : 2;
220 /** Overload standard ipairs function to use __ipairs field of metatables.
221 * \param L The Lua VM state.
222 * \return The number of elements pushed on stack.
224 static int
225 luaAe_ipairs(lua_State *L)
227 if(luaL_getmetafield(L, 1, "__ipairs"))
229 lua_insert(L, 1);
230 lua_call(L, lua_gettop(L) - 1, LUA_MULTRET);
231 return lua_gettop(L);
234 luaL_checktype(L, 1, LUA_TTABLE);
235 lua_pushvalue(L, lua_upvalueindex(1));
236 lua_pushvalue(L, 1);
237 lua_pushinteger(L, 0); /* and initial value */
238 return 3;
241 /** Enhanced type() function which recognize awesome objects.
242 * \param L The Lua VM state.
243 * \return The number of arguments pushed on the stack.
245 static int
246 luaAe_type(lua_State *L)
248 luaL_checkany(L, 1);
249 lua_pushstring(L, luaA_typename(L, 1));
250 return 1;
253 /** Replace various standards Lua functions with our own.
254 * \param L The Lua VM state.
256 static void
257 luaA_fixups(lua_State *L)
259 /* export string.wlen */
260 lua_getglobal(L, "string");
261 lua_pushcfunction(L, luaA_mbstrlen);
262 lua_setfield(L, -2, "wlen");
263 lua_pop(L, 1);
264 /* replace next */
265 lua_pushliteral(L, "next");
266 lua_pushcfunction(L, luaAe_next);
267 lua_settable(L, LUA_GLOBALSINDEX);
268 /* replace pairs */
269 lua_pushliteral(L, "pairs");
270 lua_pushcfunction(L, luaAe_next);
271 lua_pushcclosure(L, luaAe_pairs, 1); /* pairs get next as upvalue */
272 lua_settable(L, LUA_GLOBALSINDEX);
273 /* replace ipairs */
274 lua_pushliteral(L, "ipairs");
275 lua_pushcfunction(L, luaA_ipairs_aux);
276 lua_pushcclosure(L, luaAe_ipairs, 1);
277 lua_settable(L, LUA_GLOBALSINDEX);
278 /* replace type */
279 lua_pushliteral(L, "type");
280 lua_pushcfunction(L, luaAe_type);
281 lua_settable(L, LUA_GLOBALSINDEX);
282 /* set selection */
283 lua_pushliteral(L, "selection");
284 lua_pushcfunction(L, luaA_selection_get);
285 lua_settable(L, LUA_GLOBALSINDEX);
288 /** __next function for wtable objects.
289 * \param L The Lua VM state.
290 * \return The number of elements pushed on stack.
292 static int
293 luaA_wtable_next(lua_State *L)
295 /* upvalue 1 is content table */
296 if(lua_next(L, lua_upvalueindex(1)))
297 return 2;
298 lua_pushnil(L);
299 return 1;
302 /** __ipairs function for wtable objects.
303 * \param L The Lua VM state.
304 * \return The number of elements pushed on stack.
306 static int
307 luaA_wtable_ipairs(lua_State *L)
309 /* push ipairs_aux */
310 lua_pushvalue(L, lua_upvalueindex(2));
311 /* push content table */
312 lua_pushvalue(L, lua_upvalueindex(1));
313 lua_pushinteger(L, 0); /* and initial value */
314 return 3;
317 /** Index function of wtable objects.
318 * \param L The Lua VM state.
319 * \return The number of elements pushed on stack.
321 static int
322 luaA_wtable_index(lua_State *L)
324 size_t len;
325 const char *buf;
327 lua_pushvalue(L, 2);
328 /* check for size, waiting lua 5.2 and __len on tables */
329 if((buf = lua_tolstring(L, -1, &len)))
330 if(a_tokenize(buf, len) == A_TK_LEN)
332 lua_pushnumber(L, lua_objlen(L, lua_upvalueindex(1)));
333 return 1;
335 lua_pop(L, 1);
337 /* upvalue 1 is content table */
338 lua_rawget(L, lua_upvalueindex(1));
339 return 1;
342 /** Newndex function of wtable objects.
343 * \param L The Lua VM state.
344 * \return The number of elements pushed on stack.
346 static int
347 luaA_wtable_newindex(lua_State *L)
349 bool invalid = false;
351 /* push key on top */
352 lua_pushvalue(L, 2);
353 /* get current key value in content table */
354 lua_rawget(L, lua_upvalueindex(1));
355 /* if value is a widget, notify change */
356 if(lua_istable(L, -1) || luaA_toudata(L, -1, "widget"))
357 invalid = true;
359 lua_pop(L, 1); /* remove value */
361 /* if new value is a widget or a table */
362 if(lua_istable(L, 3))
364 luaA_table2wtable(L);
365 invalid = true;
367 else if(!invalid && luaA_toudata(L, 3, "widget"))
368 invalid = true;
370 /* upvalue 1 is content table */
371 lua_rawset(L, lua_upvalueindex(1));
373 if(invalid)
374 luaA_wibox_invalidate_byitem(L, lua_topointer(L, 1));
376 return 0;
379 /** Convert the top element of the stack to a proxied wtable.
380 * \param L The Lua VM state.
382 void
383 luaA_table2wtable(lua_State *L)
385 if(!lua_istable(L, -1))
386 return;
388 lua_newtable(L); /* create *real* content table */
389 lua_createtable(L, 0, 5); /* metatable */
390 lua_pushvalue(L, -2); /* copy content table */
391 lua_pushcfunction(L, luaA_ipairs_aux); /* push ipairs aux */
392 lua_pushcclosure(L, luaA_wtable_ipairs, 2);
393 lua_pushvalue(L, -3); /* copy content table */
394 lua_pushcclosure(L, luaA_wtable_next, 1); /* __next has the content table as upvalue */
395 lua_pushvalue(L, -4); /* copy content table */
396 lua_pushcclosure(L, luaA_wtable_index, 1); /* __index has the content table as upvalue */
397 lua_pushvalue(L, -5); /* copy content table */
398 lua_pushcclosure(L, luaA_wtable_newindex, 1); /* __newindex has the content table as upvalue */
399 /* set metatable field with just pushed closure */
400 lua_setfield(L, -5, "__newindex");
401 lua_setfield(L, -4, "__index");
402 lua_setfield(L, -3, "__next");
403 lua_setfield(L, -2, "__ipairs");
404 /* set metatable impossible to touch */
405 lua_pushliteral(L, "wtable");
406 lua_setfield(L, -2, "__metatable");
407 /* set new metatable on original table */
408 lua_setmetatable(L, -3);
410 /* initial key */
411 lua_pushnil(L);
412 /* go through original table */
413 while(lua_next(L, -3))
415 /* if convert value to wtable */
416 luaA_table2wtable(L);
417 /* copy key */
418 lua_pushvalue(L, -2);
419 /* move key before value */
420 lua_insert(L, -2);
421 /* set same value in content table */
422 lua_rawset(L, -4);
423 /* copy key */
424 lua_pushvalue(L, -1);
425 /* push the new value :-> */
426 lua_pushnil(L);
427 /* set orig[k] = nil */
428 lua_rawset(L, -5);
430 /* remove content table */
431 lua_pop(L, 1);
434 /** Look for an item: table, function, etc.
435 * \param L The Lua VM state.
436 * \param item The pointer item.
438 bool
439 luaA_hasitem(lua_State *L, const void *item)
441 lua_pushnil(L);
442 while(luaA_next(L, -2))
444 if(lua_topointer(L, -1) == item)
446 /* remove value and key */
447 lua_pop(L, 2);
448 return true;
450 if(lua_istable(L, -1))
451 if(luaA_hasitem(L, item))
453 /* remove key and value */
454 lua_pop(L, 2);
455 return true;
457 /* remove value */
458 lua_pop(L, 1);
460 return false;
463 /** Browse a table pushed on top of the index, and put all its table and
464 * sub-table into an array.
465 * \param L The Lua VM state.
466 * \param elems The elements array.
467 * \return False if we encounter an elements already in list.
469 static bool
470 luaA_isloop_check(lua_State *L, cptr_array_t *elems)
472 if(lua_istable(L, -1))
474 const void *object = lua_topointer(L, -1);
476 /* Check that the object table is not already in the list */
477 for(int i = 0; i < elems->len; i++)
478 if(elems->tab[i] == object)
479 return false;
481 /* push the table in the elements list */
482 cptr_array_append(elems, object);
484 /* look every object in the "table" */
485 lua_pushnil(L);
486 while(luaA_next(L, -2))
488 if(!luaA_isloop_check(L, elems))
490 /* remove key and value */
491 lua_pop(L, 2);
492 return false;
494 /* remove value, keep key for next iteration */
495 lua_pop(L, 1);
498 return true;
501 /** Check if a table is a loop. When using tables as direct acyclic digram,
502 * this is useful.
503 * \param L The Lua VM state.
504 * \param idx The index of the table in the stack
505 * \return True if the table loops.
507 bool
508 luaA_isloop(lua_State *L, int idx)
510 /* elems is an elements array that we will fill with all array we
511 * encounter while browsing the tables */
512 cptr_array_t elems;
514 cptr_array_init(&elems);
516 /* push table on top */
517 lua_pushvalue(L, idx);
519 bool ret = luaA_isloop_check(L, &elems);
521 /* remove pushed table */
522 lua_pop(L, 1);
524 cptr_array_wipe(&elems);
526 return !ret;
529 /** awesome global table.
530 * \param L The Lua VM state.
531 * \return The number of elements pushed on stack.
532 * \luastack
533 * \lfield font The default font.
534 * \lfield font_height The default font height.
535 * \lfield conffile The configuration file which has been loaded.
537 static int
538 luaA_awesome_index(lua_State *L)
540 if(luaA_usemetatable(L, 1, 2))
541 return 1;
543 size_t len;
544 const char *buf = luaL_checklstring(L, 2, &len);
546 switch(a_tokenize(buf, len))
548 case A_TK_FONT:
550 char *font = pango_font_description_to_string(globalconf.font->desc);
551 lua_pushstring(L, font);
552 g_free(font);
554 break;
555 case A_TK_FONT_HEIGHT:
556 lua_pushnumber(L, globalconf.font->height);
557 break;
558 case A_TK_CONFFILE:
559 lua_pushstring(L, globalconf.conffile);
560 break;
561 case A_TK_FG:
562 luaA_pushxcolor(L, &globalconf.colors.fg);
563 break;
564 case A_TK_BG:
565 luaA_pushxcolor(L, &globalconf.colors.bg);
566 break;
567 case A_TK_VERSION:
568 lua_pushliteral(L, AWESOME_VERSION);
569 break;
570 case A_TK_RELEASE:
571 lua_pushliteral(L, AWESOME_RELEASE);
572 break;
573 default:
574 return 0;
577 return 1;
580 /** Newindex function for the awesome global table.
581 * \param L The Lua VM state.
582 * \return The number of elements pushed on stack.
584 static int
585 luaA_awesome_newindex(lua_State *L)
587 if(luaA_usemetatable(L, 1, 2))
588 return 1;
590 size_t len;
591 const char *buf = luaL_checklstring(L, 2, &len);
593 switch(a_tokenize(buf, len))
595 case A_TK_FONT:
597 const char *newfont = luaL_checkstring(L, 3);
598 draw_font_delete(&globalconf.font);
599 globalconf.font = draw_font_new(newfont);
600 /* refresh all wiboxes */
601 foreach(wibox, globalconf.wiboxes)
602 (*wibox)->need_update = true;
603 foreach(c, globalconf.clients)
604 if((*c)->titlebar)
605 (*c)->titlebar->need_update = true;
607 break;
608 case A_TK_FG:
609 if((buf = luaL_checklstring(L, 3, &len)))
610 xcolor_init_reply(xcolor_init_unchecked(&globalconf.colors.fg, buf, len));
611 break;
612 case A_TK_BG:
613 if((buf = luaL_checklstring(L, 3, &len)))
614 xcolor_init_reply(xcolor_init_unchecked(&globalconf.colors.bg, buf, len));
615 break;
616 default:
617 return 0;
620 return 0;
623 /** Initialize the Lua VM
624 * \param xdg An xdg handle to use to get XDG basedir.
626 void
627 luaA_init(xdgHandle* xdg)
629 lua_State *L;
630 static const struct luaL_reg awesome_lib[] =
632 { "quit", luaA_quit },
633 { "exec", luaA_exec },
634 { "spawn", luaA_spawn },
635 { "restart", luaA_restart },
636 { "__index", luaA_awesome_index },
637 { "__newindex", luaA_awesome_newindex },
638 { NULL, NULL }
641 L = globalconf.L = luaL_newstate();
643 luaL_openlibs(L);
645 luaA_fixups(L);
647 luaA_object_setup(L);
649 /* Export awesome lib */
650 luaA_openlib(L, "awesome", awesome_lib, awesome_lib);
652 /* Export root */
653 luaA_openlib(L, "root", awesome_root_methods, awesome_root_meta);
655 /* Export hooks lib */
656 luaL_register(L, "hooks", awesome_hooks_lib);
657 lua_pop(L, 1); /* luaL_register() leaves the table on stack */
659 #ifdef WITH_DBUS
660 /* Export D-Bus lib */
661 luaL_register(L, "dbus", awesome_dbus_lib);
662 lua_pop(L, 1); /* luaL_register() leaves the table on stack */
663 #endif
665 /* Export keygrabber lib */
666 luaL_register(L, "keygrabber", awesome_keygrabber_lib);
667 lua_pop(L, 1); /* luaL_register() leaves the table on stack */
669 /* Export mousegrabber lib */
670 luaL_register(L, "mousegrabber", awesome_mousegrabber_lib);
671 lua_pop(L, 1); /* luaL_register() leaves the table on stack */
673 /* Export screen */
674 luaA_openlib(L, "screen", awesome_screen_methods, awesome_screen_meta);
676 /* Export mouse */
677 luaA_openlib(L, "mouse", awesome_mouse_methods, awesome_mouse_meta);
679 /* Export button */
680 luaA_class_setup(L, &button_class, "button", (lua_class_allocator_t) button_new,
681 awesome_button_methods, awesome_button_meta);
683 /* Export image */
684 luaA_class_setup(L, &image_class, "image", (lua_class_allocator_t) image_new,
685 awesome_image_methods, awesome_image_meta);
687 /* Export tag */
688 luaA_class_setup(L, &tag_class, "tag", (lua_class_allocator_t) tag_new,
689 awesome_tag_methods, awesome_tag_meta);
691 /* Export wibox */
692 luaA_class_setup(L, &wibox_class, "wibox", (lua_class_allocator_t) wibox_new,
693 awesome_wibox_methods, awesome_wibox_meta);
695 /* Export widget */
696 luaA_class_setup(L, &widget_class, "widget", (lua_class_allocator_t) widget_new,
697 awesome_widget_methods, awesome_widget_meta);
699 /* Export client */
700 luaA_class_setup(L, &client_class, "client", (lua_class_allocator_t) client_new,
701 awesome_client_methods, awesome_client_meta);
703 /* Export keys */
704 luaA_class_setup(L, &key_class, "key", (lua_class_allocator_t) key_new,
705 awesome_key_methods, awesome_key_meta);
707 /* init hooks */
708 globalconf.hooks.manage = LUA_REFNIL;
709 globalconf.hooks.unmanage = LUA_REFNIL;
710 globalconf.hooks.focus = LUA_REFNIL;
711 globalconf.hooks.unfocus = LUA_REFNIL;
712 globalconf.hooks.mouse_enter = LUA_REFNIL;
713 globalconf.hooks.mouse_leave = LUA_REFNIL;
714 globalconf.hooks.clients = LUA_REFNIL;
715 globalconf.hooks.tags = LUA_REFNIL;
716 globalconf.hooks.tagged = LUA_REFNIL;
717 globalconf.hooks.property = LUA_REFNIL;
718 globalconf.hooks.startup_notification = LUA_REFNIL;
719 globalconf.hooks.timer = LUA_REFNIL;
720 globalconf.hooks.exit = LUA_REFNIL;
722 /* add Lua lib path (/usr/share/awesome/lib by default) */
723 lua_getglobal(L, "package");
724 if (LUA_TTABLE != lua_type(L, 1))
726 warn("package is not a table");
727 return;
729 lua_getfield(L, 1, "path");
730 if (LUA_TSTRING != lua_type(L, 2))
732 warn("package.path is not a string");
733 lua_pop(L, 1);
734 return;
736 lua_pushliteral(L, ";" AWESOME_LUA_LIB_PATH "/?.lua");
737 lua_pushliteral(L, ";" AWESOME_LUA_LIB_PATH "/?/init.lua");
738 lua_concat(L, 3); /* concatenate with package.path */
740 /* add XDG_CONFIG_DIR as include path */
741 const char * const *xdgconfigdirs = xdgSearchableConfigDirectories(xdg);
742 for(; *xdgconfigdirs; xdgconfigdirs++)
744 size_t len = a_strlen(*xdgconfigdirs);
745 lua_pushliteral(L, ";");
746 lua_pushlstring(L, *xdgconfigdirs, len);
747 lua_pushliteral(L, "/awesome/?.lua");
748 lua_concat(L, 3);
750 lua_pushliteral(L, ";");
751 lua_pushlstring(L, *xdgconfigdirs, len);
752 lua_pushliteral(L, "/awesome/?/init.lua");
753 lua_concat(L, 3);
755 lua_concat(L, 3); /* concatenate with package.path */
757 lua_setfield(L, 1, "path"); /* package.path = "concatenated string" */
760 static bool
761 luaA_loadrc(const char *confpath, bool run)
763 if(!luaL_loadfile(globalconf.L, confpath))
765 if(run)
767 if(lua_pcall(globalconf.L, 0, LUA_MULTRET, 0))
768 fprintf(stderr, "%s\n", lua_tostring(globalconf.L, -1));
769 else
771 globalconf.conffile = a_strdup(confpath);
772 return true;
775 else
776 lua_pop(globalconf.L, 1);
777 return true;
779 else
780 fprintf(stderr, "%s\n", lua_tostring(globalconf.L, -1));
782 return false;
785 /** Load a configuration file.
786 * \param xdg An xdg handle to use to get XDG basedir.
787 * \param confpatharg The configuration file to load.
788 * \param run Run the configuration file.
790 bool
791 luaA_parserc(xdgHandle* xdg, const char *confpatharg, bool run)
793 char *confpath = NULL;
794 bool ret = false;
796 /* try to load, return if it's ok */
797 if(confpatharg)
799 if(luaA_loadrc(confpatharg, run))
801 ret = true;
802 goto bailout;
804 else if(!run)
805 goto bailout;
808 confpath = xdgConfigFind("awesome/rc.lua", xdg);
810 char *tmp = confpath;
812 /* confpath is "string1\0string2\0string3\0\0" */
813 while(*tmp)
815 if(luaA_loadrc(tmp, run))
817 ret = true;
818 goto bailout;
820 else if(!run)
821 goto bailout;
822 tmp += a_strlen(tmp) + 1;
825 bailout:
827 p_delete(&confpath);
829 return ret;
832 void
833 luaA_on_timer(EV_P_ ev_timer *w, int revents)
835 if(globalconf.hooks.timer != LUA_REFNIL)
836 luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.timer, 0, 0);
839 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80