/* * luaa.h - Lua configuration management header * * Copyright © 2008-2009 Julien Danjou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #ifndef AWESOME_LUA_H #define AWESOME_LUA_H #include #include #include #include #include "draw.h" #include "common/lualib.h" #define luaA_deprecate(L, repl) \ do { \ luaA_warn(L, "%s: This function is deprecated and will be removed, see %s", \ __FUNCTION__, repl); \ lua_pushlstring(L, __FUNCTION__, sizeof(__FUNCTION__)); \ signal_object_emit(L, &global_signals, "debug::deprecation", 1); \ } while(0) static inline bool luaA_checkboolean(lua_State *L, int n) { if(!lua_isboolean(L, n)) luaL_typerror(L, n, "boolean"); return lua_toboolean(L, n); } static inline lua_Number luaA_getopt_number(lua_State *L, int idx, const char *name, lua_Number def) { lua_getfield(L, idx, name); if (lua_isnil(L, -1) || lua_isnumber(L, -1)) def = luaL_optnumber(L, -1, def); lua_pop(L, 1); return def; } /** Print a warning about some Lua code. * This is less mean than luaL_error() which setjmp via lua_error() and kills * everything. This only warn, it's up to you to then do what's should be done. * \param L The Lua VM state. * \param fmt The warning message. */ static inline void __attribute__ ((format(printf, 2, 3))) luaA_warn(lua_State *L, const char *fmt, ...) { va_list ap; luaL_where(L, 1); fprintf(stderr, "%sW: ", lua_tostring(L, -1)); lua_pop(L, 1); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, "\n"); } void luaA_init(xdgHandle *); bool luaA_parserc(xdgHandle *, const char *, bool); /** Global signals */ signal_array_t global_signals; /** Our main Lua state */ lua_State *_G_L; #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80