2 * luaa.h - Lua configuration management header
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.
31 #include "common/lualib.h"
32 #include "common/luaclass.h"
34 #define luaA_deprecate(L, repl) \
36 luaA_warn(L, "%s: This function is deprecated and will be removed, see %s", \
37 __FUNCTION__, repl); \
38 lua_pushlstring(L, __FUNCTION__, sizeof(__FUNCTION__)); \
39 signal_object_emit(L, &global_signals, "debug::deprecation", 1); \
42 /** Print a warning about some Lua code.
43 * This is less mean than luaL_error() which setjmp via lua_error() and kills
44 * everything. This only warn, it's up to you to then do what's should be done.
45 * \param L The Lua VM state.
46 * \param fmt The warning message.
48 static inline void __attribute__ ((format(printf
, 2, 3)))
49 luaA_warn(lua_State
*L
, const char *fmt
, ...)
53 fprintf(stderr
, "%sW: ", lua_tostring(L
, -1));
56 vfprintf(stderr
, fmt
, ap
);
58 fprintf(stderr
, "\n");
62 luaA_typerror(lua_State
*L
, int narg
, const char *tname
)
64 const char *msg
= lua_pushfstring(L
, "%s expected, got %s",
65 tname
, luaL_typename(L
, narg
));
66 return luaL_argerror(L
, narg
, msg
);
70 luaA_getuservalue(lua_State
*L
, int idx
)
72 #if LUA_VERSION_NUM >= 502
73 lua_getuservalue(L
, idx
);
80 luaA_setuservalue(lua_State
*L
, int idx
)
82 #if LUA_VERSION_NUM >= 502
83 lua_setuservalue(L
, idx
);
90 luaA_rawlen(lua_State
*L
, int idx
)
92 #if LUA_VERSION_NUM >= 502
93 return lua_rawlen(L
, idx
);
95 return lua_objlen(L
, idx
);
100 luaA_registerlib(lua_State
*L
, const char *libname
, const luaL_Reg
*l
)
102 #if LUA_VERSION_NUM >= 502
106 luaL_setfuncs(L
, l
, 0);
107 lua_pushvalue(L
, -1);
108 lua_setglobal(L
, libname
);
111 luaL_setfuncs(L
, l
, 0);
113 luaL_register(L
, libname
, l
);
118 luaA_checkboolean(lua_State
*L
, int n
)
120 if(!lua_isboolean(L
, n
))
121 luaA_typerror(L
, n
, "boolean");
122 return lua_toboolean(L
, n
);
125 static inline lua_Number
126 luaA_getopt_number(lua_State
*L
, int idx
, const char *name
, lua_Number def
)
128 lua_getfield(L
, idx
, name
);
129 if (lua_isnil(L
, -1) || lua_isnumber(L
, -1))
130 def
= luaL_optnumber(L
, -1, def
);
135 /** Push a area type to a table on stack.
136 * \param L The Lua VM state.
137 * \param geometry The area geometry to push.
138 * \return The number of elements pushed on stack.
141 luaA_pusharea(lua_State
*L
, area_t geometry
)
143 lua_createtable(L
, 0, 4);
144 lua_pushnumber(L
, geometry
.x
);
145 lua_setfield(L
, -2, "x");
146 lua_pushnumber(L
, geometry
.y
);
147 lua_setfield(L
, -2, "y");
148 lua_pushnumber(L
, geometry
.width
);
149 lua_setfield(L
, -2, "width");
150 lua_pushnumber(L
, geometry
.height
);
151 lua_setfield(L
, -2, "height");
155 /** Register an Lua object.
156 * \param L The Lua stack.
157 * \param idx Index of the object in the stack.
158 * \param ref A int address: it will be filled with the int
159 * registered. If the address points to an already registered object, it will
164 luaA_register(lua_State
*L
, int idx
, int *ref
)
166 lua_pushvalue(L
, idx
);
167 if(*ref
!= LUA_REFNIL
)
168 luaL_unref(L
, LUA_REGISTRYINDEX
, *ref
);
169 *ref
= luaL_ref(L
, LUA_REGISTRYINDEX
);
173 /** Unregister a Lua object.
174 * \param L The Lua stack.
175 * \param ref A reference to an Lua object.
178 luaA_unregister(lua_State
*L
, int *ref
)
180 luaL_unref(L
, LUA_REGISTRYINDEX
, *ref
);
184 /** Register a function.
185 * \param L The Lua stack.
186 * \param idx Index of the function in the stack.
187 * \param fct A int address: it will be filled with the int
188 * registered. If the address points to an already registered function, it will
190 * \return luaA_register value.
193 luaA_registerfct(lua_State
*L
, int idx
, int *fct
)
195 luaA_checkfunction(L
, idx
);
196 return luaA_register(L
, idx
, fct
);
199 void luaA_init(xdgHandle
*);
200 bool luaA_parserc(xdgHandle
*, const char *, bool);
202 /** Global signals */
203 signal_array_t global_signals
;
205 int luaA_class_index_miss_property(lua_State
*, lua_object_t
*);
206 int luaA_class_newindex_miss_property(lua_State
*, lua_object_t
*);
207 int luaA_default_index(lua_State
*);
208 int luaA_default_newindex(lua_State
*);
210 void luaA_systray_invalidate(void);
213 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80