Revert "key, button: use as simple table"
[awesome.git] / luaa.c
blob5f7d23b6045f8d523e5e0a3510e3633c3a0e8719
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_lib[];
53 extern const struct luaL_reg awesome_button_methods[];
54 extern const struct luaL_reg awesome_button_meta[];
55 extern const struct luaL_reg awesome_image_methods[];
56 extern const struct luaL_reg awesome_image_meta[];
57 extern const struct luaL_reg awesome_mouse_methods[];
58 extern const struct luaL_reg awesome_mouse_meta[];
59 extern const struct luaL_reg awesome_screen_methods[];
60 extern const struct luaL_reg awesome_screen_meta[];
61 extern const struct luaL_reg awesome_client_methods[];
62 extern const struct luaL_reg awesome_client_meta[];
63 extern const struct luaL_reg awesome_tag_methods[];
64 extern const struct luaL_reg awesome_tag_meta[];
65 extern const struct luaL_reg awesome_widget_methods[];
66 extern const struct luaL_reg awesome_widget_meta[];
67 extern const struct luaL_reg awesome_wibox_methods[];
68 extern const struct luaL_reg awesome_wibox_meta[];
69 extern const struct luaL_reg awesome_key_methods[];
70 extern const struct luaL_reg awesome_key_meta[];
72 /** Quit awesome.
73 * \param L The Lua VM state.
74 * \return The number of elements pushed on stack.
76 static int
77 luaA_quit(lua_State *L __attribute__ ((unused)))
79 ev_unloop(globalconf.loop, 1);
80 return 0;
83 /** Execute another application, probably a window manager, to replace
84 * awesome.
85 * \param L The Lua VM state.
86 * \return The number of elements pushed on stack.
87 * \luastack
88 * \lparam The command line to execute.
90 static int
91 luaA_exec(lua_State *L)
93 const char *cmd = luaL_checkstring(L, 1);
95 awesome_atexit();
97 a_exec(cmd);
98 return 0;
101 /** Restart awesome.
103 static int
104 luaA_restart(lua_State *L __attribute__ ((unused)))
106 awesome_restart();
107 return 0;
110 /** UTF-8 aware string length computing.
111 * \param L The Lua VM state.
112 * \return The number of elements pushed on stack.
114 static int
115 luaA_mbstrlen(lua_State *L)
117 const char *cmd = luaL_checkstring(L, 1);
118 lua_pushnumber(L, (ssize_t) mbstowcs(NULL, NONULL(cmd), 0));
119 return 1;
122 /** Overload standard Lua next function to use __next key on metatable.
123 * \param L The Lua VM state.
124 * \return The number of elements pushed on stack.
126 static int
127 luaAe_next(lua_State *L)
129 if(luaL_getmetafield(L, 1, "__next"))
131 lua_insert(L, 1);
132 lua_call(L, lua_gettop(L) - 1, LUA_MULTRET);
133 return lua_gettop(L);
136 luaL_checktype(L, 1, LUA_TTABLE);
137 lua_settop(L, 2);
138 if(lua_next(L, 1))
139 return 2;
140 lua_pushnil(L);
141 return 1;
144 /** Overload lua_next() function by using __next metatable field
145 * to get next elements.
146 * \param L The Lua VM stack.
147 * \param idx The index number of elements in stack.
148 * \return 1 if more elements to come, 0 otherwise.
151 luaA_next(lua_State *L, int idx)
153 if(luaL_getmetafield(L, idx, "__next"))
155 /* if idx is relative, reduce it since we got __next */
156 if(idx < 0) idx--;
157 /* copy table and then move key */
158 lua_pushvalue(L, idx);
159 lua_pushvalue(L, -3);
160 lua_remove(L, -4);
161 lua_pcall(L, 2, 2, 0);
162 /* next returned nil, it's the end */
163 if(lua_isnil(L, -1))
165 /* remove nil */
166 lua_pop(L, 2);
167 return 0;
169 return 1;
171 else if(lua_istable(L, idx))
172 return lua_next(L, idx);
173 /* remove the key */
174 lua_pop(L, 1);
175 return 0;
178 /** Generic pairs function.
179 * \param L The Lua VM state.
180 * \return The number of elements pushed on stack.
182 static int
183 luaA_generic_pairs(lua_State *L)
185 lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
186 lua_pushvalue(L, 1); /* state, */
187 lua_pushnil(L); /* and initial value */
188 return 3;
191 /** Overload standard pairs function to use __pairs field of metatables.
192 * \param L The Lua VM state.
193 * \return The number of elements pushed on stack.
195 static int
196 luaAe_pairs(lua_State *L)
198 if(luaL_getmetafield(L, 1, "__pairs"))
200 lua_insert(L, 1);
201 lua_call(L, lua_gettop(L) - 1, LUA_MULTRET);
202 return lua_gettop(L);
205 luaL_checktype(L, 1, LUA_TTABLE);
206 return luaA_generic_pairs(L);
209 static int
210 luaA_ipairs_aux(lua_State *L)
212 int i = luaL_checkint(L, 2) + 1;
213 luaL_checktype(L, 1, LUA_TTABLE);
214 lua_pushinteger(L, i);
215 lua_rawgeti(L, 1, i);
216 return (lua_isnil(L, -1)) ? 0 : 2;
219 /** Overload standard ipairs function to use __ipairs field of metatables.
220 * \param L The Lua VM state.
221 * \return The number of elements pushed on stack.
223 static int
224 luaAe_ipairs(lua_State *L)
226 if(luaL_getmetafield(L, 1, "__ipairs"))
228 lua_insert(L, 1);
229 lua_call(L, lua_gettop(L) - 1, LUA_MULTRET);
230 return lua_gettop(L);
233 luaL_checktype(L, 1, LUA_TTABLE);
234 lua_pushvalue(L, lua_upvalueindex(1));
235 lua_pushvalue(L, 1);
236 lua_pushinteger(L, 0); /* and initial value */
237 return 3;
240 /** Enhanced type() function which recognize awesome objects.
241 * \param L The Lua VM state.
242 * \return The number of arguments pushed on the stack.
244 static int
245 luaAe_type(lua_State *L)
247 luaL_checkany(L, 1);
248 lua_pushstring(L, luaA_typename(L, 1));
249 return 1;
252 /** Replace various standards Lua functions with our own.
253 * \param L The Lua VM state.
255 static void
256 luaA_fixups(lua_State *L)
258 /* export string.wlen */
259 lua_getglobal(L, "string");
260 lua_pushcfunction(L, luaA_mbstrlen);
261 lua_setfield(L, -2, "wlen");
262 lua_pop(L, 1);
263 /* replace next */
264 lua_pushliteral(L, "next");
265 lua_pushcfunction(L, luaAe_next);
266 lua_settable(L, LUA_GLOBALSINDEX);
267 /* replace pairs */
268 lua_pushliteral(L, "pairs");
269 lua_pushcfunction(L, luaAe_next);
270 lua_pushcclosure(L, luaAe_pairs, 1); /* pairs get next as upvalue */
271 lua_settable(L, LUA_GLOBALSINDEX);
272 /* replace ipairs */
273 lua_pushliteral(L, "ipairs");
274 lua_pushcfunction(L, luaA_ipairs_aux);
275 lua_pushcclosure(L, luaAe_ipairs, 1);
276 lua_settable(L, LUA_GLOBALSINDEX);
277 /* replace type */
278 lua_pushliteral(L, "type");
279 lua_pushcfunction(L, luaAe_type);
280 lua_settable(L, LUA_GLOBALSINDEX);
281 /* set selection */
282 lua_pushliteral(L, "selection");
283 lua_pushcfunction(L, luaA_selection_get);
284 lua_settable(L, LUA_GLOBALSINDEX);
287 /** __next function for wtable objects.
288 * \param L The Lua VM state.
289 * \return The number of elements pushed on stack.
291 static int
292 luaA_wtable_next(lua_State *L)
294 /* upvalue 1 is content table */
295 if(lua_next(L, lua_upvalueindex(1)))
296 return 2;
297 lua_pushnil(L);
298 return 1;
301 /** __ipairs function for wtable objects.
302 * \param L The Lua VM state.
303 * \return The number of elements pushed on stack.
305 static int
306 luaA_wtable_ipairs(lua_State *L)
308 /* push ipairs_aux */
309 lua_pushvalue(L, lua_upvalueindex(2));
310 /* push content table */
311 lua_pushvalue(L, lua_upvalueindex(1));
312 lua_pushinteger(L, 0); /* and initial value */
313 return 3;
316 /** Index function of wtable objects.
317 * \param L The Lua VM state.
318 * \return The number of elements pushed on stack.
320 static int
321 luaA_wtable_index(lua_State *L)
323 size_t len;
324 const char *buf;
326 lua_pushvalue(L, 2);
327 /* check for size, waiting lua 5.2 and __len on tables */
328 if((buf = lua_tolstring(L, -1, &len)))
329 if(a_tokenize(buf, len) == A_TK_LEN)
331 lua_pushnumber(L, lua_objlen(L, lua_upvalueindex(1)));
332 return 1;
334 lua_pop(L, 1);
336 /* upvalue 1 is content table */
337 lua_rawget(L, lua_upvalueindex(1));
338 return 1;
341 /** Newndex function of wtable objects.
342 * \param L The Lua VM state.
343 * \return The number of elements pushed on stack.
345 static int
346 luaA_wtable_newindex(lua_State *L)
348 bool invalid = false;
350 /* push key on top */
351 lua_pushvalue(L, 2);
352 /* get current key value in content table */
353 lua_rawget(L, lua_upvalueindex(1));
354 /* if value is a widget, notify change */
355 if(lua_istable(L, -1) || luaA_toudata(L, -1, "widget"))
356 invalid = true;
358 lua_pop(L, 1); /* remove value */
360 /* if new value is a widget or a table */
361 if(lua_istable(L, 3))
363 luaA_table2wtable(L);
364 invalid = true;
366 else if(!invalid && luaA_toudata(L, 3, "widget"))
367 invalid = true;
369 /* upvalue 1 is content table */
370 lua_rawset(L, lua_upvalueindex(1));
372 if(invalid)
373 luaA_wibox_invalidate_byitem(L, lua_topointer(L, 1));
375 return 0;
378 /** Convert the top element of the stack to a proxied wtable.
379 * \param L The Lua VM state.
381 void
382 luaA_table2wtable(lua_State *L)
384 if(!lua_istable(L, -1))
385 return;
387 lua_newtable(L); /* create *real* content table */
388 lua_createtable(L, 0, 5); /* metatable */
389 lua_pushvalue(L, -2); /* copy content table */
390 lua_pushcfunction(L, luaA_ipairs_aux); /* push ipairs aux */
391 lua_pushcclosure(L, luaA_wtable_ipairs, 2);
392 lua_pushvalue(L, -3); /* copy content table */
393 lua_pushcclosure(L, luaA_wtable_next, 1); /* __next has the content table as upvalue */
394 lua_pushvalue(L, -4); /* copy content table */
395 lua_pushcclosure(L, luaA_wtable_index, 1); /* __index has the content table as upvalue */
396 lua_pushvalue(L, -5); /* copy content table */
397 lua_pushcclosure(L, luaA_wtable_newindex, 1); /* __newindex has the content table as upvalue */
398 /* set metatable field with just pushed closure */
399 lua_setfield(L, -5, "__newindex");
400 lua_setfield(L, -4, "__index");
401 lua_setfield(L, -3, "__next");
402 lua_setfield(L, -2, "__ipairs");
403 /* set metatable impossible to touch */
404 lua_pushliteral(L, "wtable");
405 lua_setfield(L, -2, "__metatable");
406 /* set new metatable on original table */
407 lua_setmetatable(L, -3);
409 /* initial key */
410 lua_pushnil(L);
411 /* go through original table */
412 while(lua_next(L, -3))
414 /* if convert value to wtable */
415 luaA_table2wtable(L);
416 /* copy key */
417 lua_pushvalue(L, -2);
418 /* move key before value */
419 lua_insert(L, -2);
420 /* set same value in content table */
421 lua_rawset(L, -4);
422 /* copy key */
423 lua_pushvalue(L, -1);
424 /* push the new value :-> */
425 lua_pushnil(L);
426 /* set orig[k] = nil */
427 lua_rawset(L, -5);
429 /* remove content table */
430 lua_pop(L, 1);
433 /** Look for an item: table, function, etc.
434 * \param L The Lua VM state.
435 * \param item The pointer item.
437 bool
438 luaA_hasitem(lua_State *L, const void *item)
440 lua_pushnil(L);
441 while(luaA_next(L, -2))
443 if(lua_topointer(L, -1) == item)
445 /* remove value and key */
446 lua_pop(L, 2);
447 return true;
449 if(lua_istable(L, -1))
450 if(luaA_hasitem(L, item))
452 /* remove key and value */
453 lua_pop(L, 2);
454 return true;
456 /* remove value */
457 lua_pop(L, 1);
459 return false;
462 /** Browse a table pushed on top of the index, and put all its table and
463 * sub-table into an array.
464 * \param L The Lua VM state.
465 * \param elems The elements array.
466 * \return False if we encounter an elements already in list.
468 static bool
469 luaA_isloop_check(lua_State *L, cptr_array_t *elems)
471 if(lua_istable(L, -1))
473 const void *object = lua_topointer(L, -1);
475 /* Check that the object table is not already in the list */
476 for(int i = 0; i < elems->len; i++)
477 if(elems->tab[i] == object)
478 return false;
480 /* push the table in the elements list */
481 cptr_array_append(elems, object);
483 /* look every object in the "table" */
484 lua_pushnil(L);
485 while(luaA_next(L, -2))
487 if(!luaA_isloop_check(L, elems))
489 /* remove key and value */
490 lua_pop(L, 2);
491 return false;
493 /* remove value, keep key for next iteration */
494 lua_pop(L, 1);
497 return true;
500 /** Check if a table is a loop. When using tables as direct acyclic digram,
501 * this is useful.
502 * \param L The Lua VM state.
503 * \param idx The index of the table in the stack
504 * \return True if the table loops.
506 bool
507 luaA_isloop(lua_State *L, int idx)
509 /* elems is an elements array that we will fill with all array we
510 * encounter while browsing the tables */
511 cptr_array_t elems;
513 cptr_array_init(&elems);
515 /* push table on top */
516 lua_pushvalue(L, idx);
518 bool ret = luaA_isloop_check(L, &elems);
520 /* remove pushed table */
521 lua_pop(L, 1);
523 cptr_array_wipe(&elems);
525 return !ret;
528 /** awesome global table.
529 * \param L The Lua VM state.
530 * \return The number of elements pushed on stack.
531 * \luastack
532 * \lfield font The default font.
533 * \lfield font_height The default font height.
534 * \lfield conffile The configuration file which has been loaded.
536 static int
537 luaA_awesome_index(lua_State *L)
539 if(luaA_usemetatable(L, 1, 2))
540 return 1;
542 size_t len;
543 const char *buf = luaL_checklstring(L, 2, &len);
545 switch(a_tokenize(buf, len))
547 case A_TK_FONT:
549 char *font = pango_font_description_to_string(globalconf.font->desc);
550 lua_pushstring(L, font);
551 g_free(font);
553 break;
554 case A_TK_FONT_HEIGHT:
555 lua_pushnumber(L, globalconf.font->height);
556 break;
557 case A_TK_CONFFILE:
558 lua_pushstring(L, globalconf.conffile);
559 break;
560 case A_TK_FG:
561 luaA_pushxcolor(L, &globalconf.colors.fg);
562 break;
563 case A_TK_BG:
564 luaA_pushxcolor(L, &globalconf.colors.bg);
565 break;
566 case A_TK_VERSION:
567 lua_pushliteral(L, AWESOME_VERSION);
568 break;
569 case A_TK_RELEASE:
570 lua_pushliteral(L, AWESOME_RELEASE);
571 break;
572 default:
573 return 0;
576 return 1;
579 /** Newindex function for the awesome global table.
580 * \param L The Lua VM state.
581 * \return The number of elements pushed on stack.
583 static int
584 luaA_awesome_newindex(lua_State *L)
586 if(luaA_usemetatable(L, 1, 2))
587 return 1;
589 size_t len;
590 const char *buf = luaL_checklstring(L, 2, &len);
592 switch(a_tokenize(buf, len))
594 case A_TK_FONT:
596 const char *newfont = luaL_checkstring(L, 3);
597 draw_font_delete(&globalconf.font);
598 globalconf.font = draw_font_new(newfont);
599 /* refresh all wiboxes */
600 foreach(wibox, globalconf.wiboxes)
601 (*wibox)->need_update = true;
602 foreach(c, globalconf.clients)
603 if((*c)->titlebar)
604 (*c)->titlebar->need_update = true;
606 break;
607 case A_TK_FG:
608 if((buf = luaL_checklstring(L, 3, &len)))
609 xcolor_init_reply(xcolor_init_unchecked(&globalconf.colors.fg, buf, len));
610 break;
611 case A_TK_BG:
612 if((buf = luaL_checklstring(L, 3, &len)))
613 xcolor_init_reply(xcolor_init_unchecked(&globalconf.colors.bg, buf, len));
614 break;
615 default:
616 return 0;
619 return 0;
622 /** Initialize the Lua VM
623 * \param xdg An xdg handle to use to get XDG basedir.
625 void
626 luaA_init(xdgHandle* xdg)
628 lua_State *L;
629 static const struct luaL_reg awesome_lib[] =
631 { "quit", luaA_quit },
632 { "exec", luaA_exec },
633 { "spawn", luaA_spawn },
634 { "restart", luaA_restart },
635 { "__index", luaA_awesome_index },
636 { "__newindex", luaA_awesome_newindex },
637 { NULL, NULL }
640 L = globalconf.L = luaL_newstate();
642 luaL_openlibs(L);
644 luaA_fixups(L);
646 luaA_object_setup(L);
648 /* Export awesome lib */
649 luaA_openlib(L, "awesome", awesome_lib, awesome_lib);
651 /* Export root lib */
652 luaL_register(L, "root", awesome_root_lib);
653 lua_pop(L, 1); /* luaL_register() leaves the table on stack */
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