client: update EWMH hints when changing skip_taskbar
[awesome.git] / luaa.c
blobb0232746d1d4580afeb9ee100ca0e417fb6db5d0
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 "timer.h"
34 #include "awesome-version-internal.h"
35 #include "ewmh.h"
36 #include "luaa.h"
37 #include "spawn.h"
38 #include "tag.h"
39 #include "client.h"
40 #include "screen.h"
41 #include "event.h"
42 #include "selection.h"
43 #include "window.h"
44 #include "common/xcursor.h"
45 #include "common/buffer.h"
47 #ifdef WITH_DBUS
48 extern const struct luaL_reg awesome_dbus_lib[];
49 #endif
50 extern const struct luaL_reg awesome_hooks_lib[];
51 extern const struct luaL_reg awesome_keygrabber_lib[];
52 extern const struct luaL_reg awesome_mousegrabber_lib[];
53 extern const struct luaL_reg awesome_root_lib[];
54 extern const struct luaL_reg awesome_mouse_methods[];
55 extern const struct luaL_reg awesome_mouse_meta[];
56 extern const struct luaL_reg awesome_screen_methods[];
57 extern const struct luaL_reg awesome_screen_meta[];
59 /** Quit awesome.
60 * \param L The Lua VM state.
61 * \return The number of elements pushed on stack.
63 static int
64 luaA_quit(lua_State *L __attribute__ ((unused)))
66 ev_unloop(globalconf.loop, 1);
67 return 0;
70 /** Execute another application, probably a window manager, to replace
71 * awesome.
72 * \param L The Lua VM state.
73 * \return The number of elements pushed on stack.
74 * \luastack
75 * \lparam The command line to execute.
77 static int
78 luaA_exec(lua_State *L)
80 const char *cmd = luaL_checkstring(L, 1);
82 awesome_atexit();
84 a_exec(cmd);
85 return 0;
88 /** Restart awesome.
90 static int
91 luaA_restart(lua_State *L __attribute__ ((unused)))
93 awesome_restart();
94 return 0;
97 /** UTF-8 aware string length computing.
98 * \param L The Lua VM state.
99 * \return The number of elements pushed on stack.
101 static int
102 luaA_mbstrlen(lua_State *L)
104 const char *cmd = luaL_checkstring(L, 1);
105 lua_pushnumber(L, (ssize_t) mbstowcs(NULL, NONULL(cmd), 0));
106 return 1;
109 /** Overload standard Lua next function to use __next key on metatable.
110 * \param L The Lua VM state.
111 * \return The number of elements pushed on stack.
113 static int
114 luaAe_next(lua_State *L)
116 if(luaL_getmetafield(L, 1, "__next"))
118 lua_insert(L, 1);
119 lua_call(L, lua_gettop(L) - 1, LUA_MULTRET);
120 return lua_gettop(L);
123 luaL_checktype(L, 1, LUA_TTABLE);
124 lua_settop(L, 2);
125 if(lua_next(L, 1))
126 return 2;
127 lua_pushnil(L);
128 return 1;
131 /** Overload lua_next() function by using __next metatable field
132 * to get next elements.
133 * \param L The Lua VM stack.
134 * \param idx The index number of elements in stack.
135 * \return 1 if more elements to come, 0 otherwise.
138 luaA_next(lua_State *L, int idx)
140 if(luaL_getmetafield(L, idx, "__next"))
142 /* if idx is relative, reduce it since we got __next */
143 if(idx < 0) idx--;
144 /* copy table and then move key */
145 lua_pushvalue(L, idx);
146 lua_pushvalue(L, -3);
147 lua_remove(L, -4);
148 lua_pcall(L, 2, 2, 0);
149 /* next returned nil, it's the end */
150 if(lua_isnil(L, -1))
152 /* remove nil */
153 lua_pop(L, 2);
154 return 0;
156 return 1;
158 else if(lua_istable(L, idx))
159 return lua_next(L, idx);
160 /* remove the key */
161 lua_pop(L, 1);
162 return 0;
165 /** Generic pairs function.
166 * \param L The Lua VM state.
167 * \return The number of elements pushed on stack.
169 static int
170 luaA_generic_pairs(lua_State *L)
172 lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
173 lua_pushvalue(L, 1); /* state, */
174 lua_pushnil(L); /* and initial value */
175 return 3;
178 /** Overload standard pairs function to use __pairs field of metatables.
179 * \param L The Lua VM state.
180 * \return The number of elements pushed on stack.
182 static int
183 luaAe_pairs(lua_State *L)
185 if(luaL_getmetafield(L, 1, "__pairs"))
187 lua_insert(L, 1);
188 lua_call(L, lua_gettop(L) - 1, LUA_MULTRET);
189 return lua_gettop(L);
192 luaL_checktype(L, 1, LUA_TTABLE);
193 return luaA_generic_pairs(L);
196 static int
197 luaA_ipairs_aux(lua_State *L)
199 int i = luaL_checkint(L, 2) + 1;
200 luaL_checktype(L, 1, LUA_TTABLE);
201 lua_pushinteger(L, i);
202 lua_rawgeti(L, 1, i);
203 return (lua_isnil(L, -1)) ? 0 : 2;
206 /** Overload standard ipairs function to use __ipairs field of metatables.
207 * \param L The Lua VM state.
208 * \return The number of elements pushed on stack.
210 static int
211 luaAe_ipairs(lua_State *L)
213 if(luaL_getmetafield(L, 1, "__ipairs"))
215 lua_insert(L, 1);
216 lua_call(L, lua_gettop(L) - 1, LUA_MULTRET);
217 return lua_gettop(L);
220 luaL_checktype(L, 1, LUA_TTABLE);
221 lua_pushvalue(L, lua_upvalueindex(1));
222 lua_pushvalue(L, 1);
223 lua_pushinteger(L, 0); /* and initial value */
224 return 3;
227 /** Enhanced type() function which recognize awesome objects.
228 * \param L The Lua VM state.
229 * \return The number of arguments pushed on the stack.
231 static int
232 luaAe_type(lua_State *L)
234 luaL_checkany(L, 1);
235 lua_pushstring(L, luaA_typename(L, 1));
236 return 1;
239 /** Replace various standards Lua functions with our own.
240 * \param L The Lua VM state.
242 static void
243 luaA_fixups(lua_State *L)
245 /* export string.wlen */
246 lua_getglobal(L, "string");
247 lua_pushcfunction(L, luaA_mbstrlen);
248 lua_setfield(L, -2, "wlen");
249 lua_pop(L, 1);
250 /* replace next */
251 lua_pushliteral(L, "next");
252 lua_pushcfunction(L, luaAe_next);
253 lua_settable(L, LUA_GLOBALSINDEX);
254 /* replace pairs */
255 lua_pushliteral(L, "pairs");
256 lua_pushcfunction(L, luaAe_next);
257 lua_pushcclosure(L, luaAe_pairs, 1); /* pairs get next as upvalue */
258 lua_settable(L, LUA_GLOBALSINDEX);
259 /* replace ipairs */
260 lua_pushliteral(L, "ipairs");
261 lua_pushcfunction(L, luaA_ipairs_aux);
262 lua_pushcclosure(L, luaAe_ipairs, 1);
263 lua_settable(L, LUA_GLOBALSINDEX);
264 /* replace type */
265 lua_pushliteral(L, "type");
266 lua_pushcfunction(L, luaAe_type);
267 lua_settable(L, LUA_GLOBALSINDEX);
268 /* set selection */
269 lua_pushliteral(L, "selection");
270 lua_pushcfunction(L, luaA_selection_get);
271 lua_settable(L, LUA_GLOBALSINDEX);
274 /** __next function for wtable objects.
275 * \param L The Lua VM state.
276 * \return The number of elements pushed on stack.
278 static int
279 luaA_wtable_next(lua_State *L)
281 /* upvalue 1 is content table */
282 if(lua_next(L, lua_upvalueindex(1)))
283 return 2;
284 lua_pushnil(L);
285 return 1;
288 /** __ipairs 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_ipairs(lua_State *L)
295 /* push ipairs_aux */
296 lua_pushvalue(L, lua_upvalueindex(2));
297 /* push content table */
298 lua_pushvalue(L, lua_upvalueindex(1));
299 lua_pushinteger(L, 0); /* and initial value */
300 return 3;
303 /** Index function of wtable objects.
304 * \param L The Lua VM state.
305 * \return The number of elements pushed on stack.
307 static int
308 luaA_wtable_index(lua_State *L)
310 size_t len;
311 const char *buf;
313 lua_pushvalue(L, 2);
314 /* check for size, waiting lua 5.2 and __len on tables */
315 if((buf = lua_tolstring(L, -1, &len)))
316 if(a_tokenize(buf, len) == A_TK_LEN)
318 lua_pushnumber(L, lua_objlen(L, lua_upvalueindex(1)));
319 return 1;
321 lua_pop(L, 1);
323 /* upvalue 1 is content table */
324 lua_rawget(L, lua_upvalueindex(1));
325 return 1;
328 /** Newndex function of wtable objects.
329 * \param L The Lua VM state.
330 * \return The number of elements pushed on stack.
332 static int
333 luaA_wtable_newindex(lua_State *L)
335 bool invalid = false;
337 /* push key on top */
338 lua_pushvalue(L, 2);
339 /* get current key value in content table */
340 lua_rawget(L, lua_upvalueindex(1));
341 /* if value is a widget, notify change */
342 if(lua_istable(L, -1) || luaA_toudata(L, -1, &widget_class))
343 invalid = true;
345 lua_pop(L, 1); /* remove value */
347 /* if new value is a widget or a table */
348 if(lua_istable(L, 3))
350 luaA_table2wtable(L);
351 invalid = true;
353 else if(!invalid && luaA_toudata(L, 3, &widget_class))
354 invalid = true;
356 /* upvalue 1 is content table */
357 lua_rawset(L, lua_upvalueindex(1));
359 if(invalid)
360 luaA_wibox_invalidate_byitem(L, lua_topointer(L, 1));
362 return 0;
365 /** Convert the top element of the stack to a proxied wtable.
366 * \param L The Lua VM state.
368 void
369 luaA_table2wtable(lua_State *L)
371 if(!lua_istable(L, -1))
372 return;
374 lua_newtable(L); /* create *real* content table */
375 lua_createtable(L, 0, 5); /* metatable */
376 lua_pushvalue(L, -2); /* copy content table */
377 lua_pushcfunction(L, luaA_ipairs_aux); /* push ipairs aux */
378 lua_pushcclosure(L, luaA_wtable_ipairs, 2);
379 lua_pushvalue(L, -3); /* copy content table */
380 lua_pushcclosure(L, luaA_wtable_next, 1); /* __next has the content table as upvalue */
381 lua_pushvalue(L, -4); /* copy content table */
382 lua_pushcclosure(L, luaA_wtable_index, 1); /* __index has the content table as upvalue */
383 lua_pushvalue(L, -5); /* copy content table */
384 lua_pushcclosure(L, luaA_wtable_newindex, 1); /* __newindex has the content table as upvalue */
385 /* set metatable field with just pushed closure */
386 lua_setfield(L, -5, "__newindex");
387 lua_setfield(L, -4, "__index");
388 lua_setfield(L, -3, "__next");
389 lua_setfield(L, -2, "__ipairs");
390 /* set metatable impossible to touch */
391 lua_pushliteral(L, "wtable");
392 lua_setfield(L, -2, "__metatable");
393 /* set new metatable on original table */
394 lua_setmetatable(L, -3);
396 /* initial key */
397 lua_pushnil(L);
398 /* go through original table */
399 while(lua_next(L, -3))
401 /* if convert value to wtable */
402 luaA_table2wtable(L);
403 /* copy key */
404 lua_pushvalue(L, -2);
405 /* move key before value */
406 lua_insert(L, -2);
407 /* set same value in content table */
408 lua_rawset(L, -4);
409 /* copy key */
410 lua_pushvalue(L, -1);
411 /* push the new value :-> */
412 lua_pushnil(L);
413 /* set orig[k] = nil */
414 lua_rawset(L, -5);
416 /* remove content table */
417 lua_pop(L, 1);
420 /** Look for an item: table, function, etc.
421 * \param L The Lua VM state.
422 * \param item The pointer item.
424 bool
425 luaA_hasitem(lua_State *L, const void *item)
427 lua_pushnil(L);
428 while(luaA_next(L, -2))
430 if(lua_topointer(L, -1) == item)
432 /* remove value and key */
433 lua_pop(L, 2);
434 return true;
436 if(lua_istable(L, -1))
437 if(luaA_hasitem(L, item))
439 /* remove key and value */
440 lua_pop(L, 2);
441 return true;
443 /* remove value */
444 lua_pop(L, 1);
446 return false;
449 /** Browse a table pushed on top of the index, and put all its table and
450 * sub-table into an array.
451 * \param L The Lua VM state.
452 * \param elems The elements array.
453 * \return False if we encounter an elements already in list.
455 static bool
456 luaA_isloop_check(lua_State *L, cptr_array_t *elems)
458 if(lua_istable(L, -1))
460 const void *object = lua_topointer(L, -1);
462 /* Check that the object table is not already in the list */
463 for(int i = 0; i < elems->len; i++)
464 if(elems->tab[i] == object)
465 return false;
467 /* push the table in the elements list */
468 cptr_array_append(elems, object);
470 /* look every object in the "table" */
471 lua_pushnil(L);
472 while(luaA_next(L, -2))
474 if(!luaA_isloop_check(L, elems))
476 /* remove key and value */
477 lua_pop(L, 2);
478 return false;
480 /* remove value, keep key for next iteration */
481 lua_pop(L, 1);
484 return true;
487 /** Check if a table is a loop. When using tables as direct acyclic digram,
488 * this is useful.
489 * \param L The Lua VM state.
490 * \param idx The index of the table in the stack
491 * \return True if the table loops.
493 bool
494 luaA_isloop(lua_State *L, int idx)
496 /* elems is an elements array that we will fill with all array we
497 * encounter while browsing the tables */
498 cptr_array_t elems;
500 cptr_array_init(&elems);
502 /* push table on top */
503 lua_pushvalue(L, idx);
505 bool ret = luaA_isloop_check(L, &elems);
507 /* remove pushed table */
508 lua_pop(L, 1);
510 cptr_array_wipe(&elems);
512 return !ret;
515 /** awesome global table.
516 * \param L The Lua VM state.
517 * \return The number of elements pushed on stack.
518 * \luastack
519 * \lfield font The default font.
520 * \lfield font_height The default font height.
521 * \lfield conffile The configuration file which has been loaded.
523 static int
524 luaA_awesome_index(lua_State *L)
526 if(luaA_usemetatable(L, 1, 2))
527 return 1;
529 size_t len;
530 const char *buf = luaL_checklstring(L, 2, &len);
532 switch(a_tokenize(buf, len))
534 case A_TK_FONT:
536 char *font = pango_font_description_to_string(globalconf.font->desc);
537 lua_pushstring(L, font);
538 g_free(font);
540 break;
541 case A_TK_FONT_HEIGHT:
542 lua_pushnumber(L, globalconf.font->height);
543 break;
544 case A_TK_CONFFILE:
545 lua_pushstring(L, globalconf.conffile);
546 break;
547 case A_TK_FG:
548 luaA_pushxcolor(L, globalconf.colors.fg);
549 break;
550 case A_TK_BG:
551 luaA_pushxcolor(L, globalconf.colors.bg);
552 break;
553 case A_TK_VERSION:
554 lua_pushliteral(L, AWESOME_VERSION);
555 break;
556 case A_TK_RELEASE:
557 lua_pushliteral(L, AWESOME_RELEASE);
558 break;
559 default:
560 return 0;
563 return 1;
566 /** Newindex function for the awesome global table.
567 * \param L The Lua VM state.
568 * \return The number of elements pushed on stack.
570 static int
571 luaA_awesome_newindex(lua_State *L)
573 if(luaA_usemetatable(L, 1, 2))
574 return 1;
576 size_t len;
577 const char *buf = luaL_checklstring(L, 2, &len);
579 switch(a_tokenize(buf, len))
581 case A_TK_FONT:
583 const char *newfont = luaL_checkstring(L, 3);
584 draw_font_delete(&globalconf.font);
585 globalconf.font = draw_font_new(newfont);
586 /* refresh all wiboxes */
587 foreach(wibox, globalconf.wiboxes)
588 (*wibox)->need_update = true;
589 foreach(c, globalconf.clients)
590 if((*c)->titlebar)
591 (*c)->titlebar->need_update = true;
593 break;
594 case A_TK_FG:
595 if((buf = luaL_checklstring(L, 3, &len)))
596 xcolor_init_reply(xcolor_init_unchecked(&globalconf.colors.fg, buf, len));
597 break;
598 case A_TK_BG:
599 if((buf = luaL_checklstring(L, 3, &len)))
600 xcolor_init_reply(xcolor_init_unchecked(&globalconf.colors.bg, buf, len));
601 break;
602 default:
603 return 0;
606 return 0;
609 /** Add a global signal.
610 * \param L The Lua VM state.
611 * \return The number of elements pushed on stack.
612 * \luastack
613 * \lparam A string with the event name.
614 * \lparam The function to call.
616 static int
617 luaA_awesome_add_signal(lua_State *L)
619 const char *name = luaL_checkstring(L, 1);
620 luaA_checkfunction(L, 2);
621 signal_add(&global_signals, name, luaA_object_ref(L, 2));
622 return 0;
625 /** Remove a global signal.
626 * \param L The Lua VM state.
627 * \return The number of elements pushed on stack.
628 * \luastack
629 * \lparam A string with the event name.
630 * \lparam The function to call.
632 static int
633 luaA_awesome_remove_signal(lua_State *L)
635 const char *name = luaL_checkstring(L, 1);
636 luaA_checkfunction(L, 2);
637 const void *func = lua_topointer(L, 2);
638 signal_remove(&global_signals, name, func);
639 luaA_object_unref(L, (void *) func);
640 return 0;
643 /** Emit a global signal.
644 * \param L The Lua VM state.
645 * \return The number of elements pushed on stack.
646 * \luastack
647 * \lparam A string with the event name.
648 * \lparam The function to call.
650 static int
651 luaA_awesome_emit_signal(lua_State *L)
653 signal_object_emit(L, &global_signals, luaL_checkstring(L, 1), lua_gettop(L) - 1);
654 return 0;
657 /** Initialize the Lua VM
658 * \param xdg An xdg handle to use to get XDG basedir.
660 void
661 luaA_init(xdgHandle* xdg)
663 lua_State *L;
664 static const struct luaL_reg awesome_lib[] =
666 { "quit", luaA_quit },
667 { "exec", luaA_exec },
668 { "spawn", luaA_spawn },
669 { "restart", luaA_restart },
670 { "add_signal", luaA_awesome_add_signal },
671 { "remove_signal", luaA_awesome_remove_signal },
672 { "emit_signal", luaA_awesome_emit_signal },
673 { "__index", luaA_awesome_index },
674 { "__newindex", luaA_awesome_newindex },
675 { NULL, NULL }
678 L = globalconf.L = luaL_newstate();
680 luaL_openlibs(L);
682 luaA_fixups(L);
684 luaA_object_setup(L);
686 /* Export awesome lib */
687 luaA_openlib(L, "awesome", awesome_lib, awesome_lib);
689 /* Export root lib */
690 luaL_register(L, "root", awesome_root_lib);
691 lua_pop(L, 1); /* luaL_register() leaves the table on stack */
693 /* Export hooks lib */
694 luaL_register(L, "hooks", awesome_hooks_lib);
695 lua_pop(L, 1); /* luaL_register() leaves the table on stack */
697 #ifdef WITH_DBUS
698 /* Export D-Bus lib */
699 luaL_register(L, "dbus", awesome_dbus_lib);
700 lua_pop(L, 1); /* luaL_register() leaves the table on stack */
701 #endif
703 /* Export keygrabber lib */
704 luaL_register(L, "keygrabber", awesome_keygrabber_lib);
705 lua_pop(L, 1); /* luaL_register() leaves the table on stack */
707 /* Export mousegrabber lib */
708 luaL_register(L, "mousegrabber", awesome_mousegrabber_lib);
709 lua_pop(L, 1); /* luaL_register() leaves the table on stack */
711 /* Export screen */
712 luaA_openlib(L, "screen", awesome_screen_methods, awesome_screen_meta);
714 /* Export mouse */
715 luaA_openlib(L, "mouse", awesome_mouse_methods, awesome_mouse_meta);
717 /* Export button */
718 button_class_setup(L);
720 /* Export image */
721 image_class_setup(L);
723 /* Export tag */
724 tag_class_setup(L);
726 /* Export wibox */
727 wibox_class_setup(L);
729 /* Export widget */
730 widget_class_setup(L);
732 /* Export client */
733 client_class_setup(L);
735 /* Export keys */
736 key_class_setup(L);
738 /* Export timer */
739 timer_class_setup(L);
741 /* init hooks */
742 globalconf.hooks.manage = LUA_REFNIL;
743 globalconf.hooks.unmanage = LUA_REFNIL;
744 globalconf.hooks.focus = LUA_REFNIL;
745 globalconf.hooks.unfocus = LUA_REFNIL;
746 globalconf.hooks.mouse_enter = LUA_REFNIL;
747 globalconf.hooks.mouse_leave = LUA_REFNIL;
748 globalconf.hooks.clients = LUA_REFNIL;
749 globalconf.hooks.tags = LUA_REFNIL;
750 globalconf.hooks.tagged = LUA_REFNIL;
751 globalconf.hooks.property = LUA_REFNIL;
752 globalconf.hooks.timer = LUA_REFNIL;
753 globalconf.hooks.exit = LUA_REFNIL;
755 /* add Lua lib path (/usr/share/awesome/lib by default) */
756 lua_getglobal(L, "package");
757 if (LUA_TTABLE != lua_type(L, 1))
759 warn("package is not a table");
760 return;
762 lua_getfield(L, 1, "path");
763 if (LUA_TSTRING != lua_type(L, 2))
765 warn("package.path is not a string");
766 lua_pop(L, 1);
767 return;
769 lua_pushliteral(L, ";" AWESOME_LUA_LIB_PATH "/?.lua");
770 lua_pushliteral(L, ";" AWESOME_LUA_LIB_PATH "/?/init.lua");
771 lua_concat(L, 3); /* concatenate with package.path */
773 /* add XDG_CONFIG_DIR as include path */
774 const char * const *xdgconfigdirs = xdgSearchableConfigDirectories(xdg);
775 for(; *xdgconfigdirs; xdgconfigdirs++)
777 size_t len = a_strlen(*xdgconfigdirs);
778 lua_pushliteral(L, ";");
779 lua_pushlstring(L, *xdgconfigdirs, len);
780 lua_pushliteral(L, "/awesome/?.lua");
781 lua_concat(L, 3);
783 lua_pushliteral(L, ";");
784 lua_pushlstring(L, *xdgconfigdirs, len);
785 lua_pushliteral(L, "/awesome/?/init.lua");
786 lua_concat(L, 3);
788 lua_concat(L, 3); /* concatenate with package.path */
790 lua_setfield(L, 1, "path"); /* package.path = "concatenated string" */
793 static bool
794 luaA_loadrc(const char *confpath, bool run)
796 if(!luaL_loadfile(globalconf.L, confpath))
798 if(run)
800 if(lua_pcall(globalconf.L, 0, LUA_MULTRET, 0))
801 fprintf(stderr, "%s\n", lua_tostring(globalconf.L, -1));
802 else
804 globalconf.conffile = a_strdup(confpath);
805 return true;
808 else
809 lua_pop(globalconf.L, 1);
810 return true;
812 else
813 fprintf(stderr, "%s\n", lua_tostring(globalconf.L, -1));
815 return false;
818 /** Load a configuration file.
819 * \param xdg An xdg handle to use to get XDG basedir.
820 * \param confpatharg The configuration file to load.
821 * \param run Run the configuration file.
823 bool
824 luaA_parserc(xdgHandle* xdg, const char *confpatharg, bool run)
826 char *confpath = NULL;
827 bool ret = false;
829 /* try to load, return if it's ok */
830 if(confpatharg)
832 if(luaA_loadrc(confpatharg, run))
834 ret = true;
835 goto bailout;
837 else if(!run)
838 goto bailout;
841 confpath = xdgConfigFind("awesome/rc.lua", xdg);
843 char *tmp = confpath;
845 /* confpath is "string1\0string2\0string3\0\0" */
846 while(*tmp)
848 if(luaA_loadrc(tmp, run))
850 ret = true;
851 goto bailout;
853 else if(!run)
854 goto bailout;
855 tmp += a_strlen(tmp) + 1;
858 bailout:
860 p_delete(&confpath);
862 return ret;
865 void
866 luaA_on_timer(EV_P_ ev_timer *w, int revents)
868 if(globalconf.hooks.timer != LUA_REFNIL)
869 luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.timer, 0, 0);
873 luaA_class_index_miss_property(lua_State *L, lua_object_t *obj)
875 signal_object_emit(L, &global_signals, "debug::index::miss", 2);
876 return 0;
880 luaA_class_newindex_miss_property(lua_State *L, lua_object_t *obj)
882 signal_object_emit(L, &global_signals, "debug::newindex::miss", 3);
883 return 0;
886 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80