mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-16 07:47:22 +01:00
118 lines
3.1 KiB
C
118 lines
3.1 KiB
C
|
/*
|
||
|
* lua.h - Lua configuration management header
|
||
|
*
|
||
|
* Copyright © 2008 Julien Danjou <julien@danjou.info>
|
||
|
*
|
||
|
* 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 2 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, write to the Free Software Foundation, Inc.,
|
||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#ifndef AWESOME_LUA_H
|
||
|
#define AWESOME_LUA_H
|
||
|
|
||
|
#include <lua5.1/lua.h>
|
||
|
#include <lua5.1/lauxlib.h>
|
||
|
|
||
|
#include "common/util.h"
|
||
|
|
||
|
/** Type for Lua function */
|
||
|
typedef int luaA_function;
|
||
|
|
||
|
#define luaA_dostring(L, cmd) \
|
||
|
do { \
|
||
|
if(cmd) \
|
||
|
if(luaL_dostring(L, cmd)) \
|
||
|
warn("error executing Lua code: %s\n", \
|
||
|
lua_tostring(L, -1)); \
|
||
|
} while(0)
|
||
|
|
||
|
#define luaA_dofunction(L, f, n) \
|
||
|
do { \
|
||
|
if(f) \
|
||
|
{ \
|
||
|
lua_rawgeti(L, LUA_REGISTRYINDEX, f); \
|
||
|
if(n) \
|
||
|
lua_insert(L, - (n + 1)); \
|
||
|
if(lua_pcall(L, n, 0, 0)) \
|
||
|
warn("error running function: %s\n", \
|
||
|
lua_tostring(L, -1)); \
|
||
|
} \
|
||
|
} while(0)
|
||
|
|
||
|
#define luaA_checktable(L, n) \
|
||
|
do { \
|
||
|
if(!lua_istable(L, n)) \
|
||
|
luaL_typerror(L, n, "table"); \
|
||
|
} while(0)
|
||
|
|
||
|
#define luaA_checkfunction(L, n) \
|
||
|
do { \
|
||
|
if(!lua_isfunction(L, n)) \
|
||
|
luaL_typerror(L, n, "function"); \
|
||
|
} while(0)
|
||
|
|
||
|
#define luaA_checkscreen(screen) \
|
||
|
do { \
|
||
|
if(screen < 0 || screen >= globalconf.screens_info->nscreen) \
|
||
|
luaL_error(L, "invalid screen number: %d\n", screen); \
|
||
|
} while(0)
|
||
|
|
||
|
static inline lua_Number
|
||
|
luaA_getopt_number(lua_State *L, int idx, const char *name, lua_Number def)
|
||
|
{
|
||
|
/* assume that table is first on stack */
|
||
|
lua_getfield(L, idx, name);
|
||
|
/* return luaL_optnumber result */
|
||
|
return luaL_optnumber(L, -1, def);
|
||
|
}
|
||
|
|
||
|
static inline const char *
|
||
|
luaA_getopt_string(lua_State *L, int idx, const char *name, const char *def)
|
||
|
{
|
||
|
/* assume that table is first on stack */
|
||
|
lua_getfield(L, idx, name);
|
||
|
/* return luaL_optnumber result */
|
||
|
return luaL_optstring(L, -1, def);
|
||
|
}
|
||
|
|
||
|
static inline int
|
||
|
luaA_settype(lua_State *L, const char *type)
|
||
|
{
|
||
|
luaL_getmetatable(L, type);
|
||
|
lua_setmetatable(L, -2);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
static inline char *
|
||
|
luaA_name_init(lua_State *L)
|
||
|
{
|
||
|
lua_getfield(L, 1, "name");
|
||
|
return a_strdup(luaL_checkstring(L, -1));
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
|
||
|
bool luaA_parserc(const char *);
|
||
|
void luaA_docmd(char *);
|
||
|
#endif
|
||
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|