1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

Be more intelligent about handling tolua++ user types.

This commit is contained in:
Brenden Matthews 2009-07-27 14:07:36 -06:00
parent ca0f8f8712
commit 73d36a59c0
3 changed files with 37 additions and 73 deletions

View File

@ -457,6 +457,7 @@ if test x$want_lua = xyes; then
want_lua_cairo=no want_lua_cairo=no
want_lua_imlib2=no want_lua_imlib2=no
else else
AC_DEFINE(LUA_EXTRAS, 1, [Define if you want Lua extras])
if test "x$want_x11" != "xyes"; then if test "x$want_x11" != "xyes"; then
dnl silently disable if no x11 dnl silently disable if no x11
want_lua_cairo=no want_lua_cairo=no
@ -486,7 +487,9 @@ if test x$want_lua = xyes; then
AC_MSG_ERROR([tolua_error not found]), AC_MSG_ERROR([tolua_error not found]),
$LUA51_LIBS) $LUA51_LIBS)
fi fi
conky_LIBS="$conky_LIBS $tolua_LIBS"
fi fi
fi fi
AC_DEFINE(HAVE_LUA, 1, [Define if you want Lua scripting support]) AC_DEFINE(HAVE_LUA, 1, [Define if you want Lua scripting support])
fi fi

View File

@ -27,59 +27,59 @@
<member> <member>
<command>drawable</command> <command>drawable</command>
<option>Window's drawable (Xlib <option>Window's drawable (Xlib
Drawable)</option> Drawable), requires Lua extras enabled at compile time.</option>
</member> </member>
<member> <member>
<command>visual</command> <command>visual</command>
<option>Window's visual (Xlib Visual)</option> <option>Window's visual (Xlib Visual), requires Lua extras enabled at compile time.</option>
</member> </member>
<member> <member>
<command>display</command> <command>display</command>
<option>Window's display (Xlib <option>Window's display (Xlib
Display)</option> Display), requires Lua extras enabled at compile time.</option>
</member> </member>
<member> <member>
<command>width</command> <command>width</command>
<option>Window width (in pixels)</option> <option>Window width (in pixels).</option>
</member> </member>
<member> <member>
<command>height</command> <command>height</command>
<option>Window height (in pixels)</option> <option>Window height (in pixels).</option>
</member> </member>
<member> <member>
<command>border_inner_margin</command> <command>border_inner_margin</command>
<option>Window's inner border margin (in <option>Window's inner border margin (in
pixels)</option> pixels).</option>
</member> </member>
<member> <member>
<command>border_outer_margin</command> <command>border_outer_margin</command>
<option>Window's outer border margin (in <option>Window's outer border margin (in
pixels)</option> pixels).</option>
</member> </member>
<member> <member>
<command>border_width</command> <command>border_width</command>
<option>Window's border width (in <option>Window's border width (in
pixels)</option> pixels).</option>
</member> </member>
<member> <member>
<command>text_start_x</command> <command>text_start_x</command>
<option>The x component of the starting <option>The x component of the starting
coordinate of text drawing</option> coordinate of text drawing.</option>
</member> </member>
<member> <member>
<command>text_start_y</command> <command>text_start_y</command>
<option>The y component of the starting <option>The y component of the starting
coordinate of text drawing</option> coordinate of text drawing.</option>
</member> </member>
<member> <member>
<command>text_width</command> <command>text_width</command>
<option>The width of the text drawing <option>The width of the text drawing
region</option> region.</option>
</member> </member>
<member> <member>
<command>text_height</command> <command>text_height</command>
<option>The height of the text drawing <option>The height of the text drawing
region</option> region.</option>
</member> </member>
</simplelist> </simplelist>
<para>NOTE: This table is only defined when X support <para>NOTE: This table is only defined when X support

View File

@ -23,6 +23,10 @@
#include "logging.h" #include "logging.h"
#include "build.h" #include "build.h"
#ifdef LUA_EXTRAS
#include <tolua++.h>
#endif /* LUA_EXTRAS */
#ifdef HAVE_SYS_INOTIFY_H #ifdef HAVE_SYS_INOTIFY_H
#include <sys/inotify.h> #include <sys/inotify.h>
@ -95,6 +99,14 @@ void llua_init(void)
lua_pushcfunction(lua_L, &llua_conky_parse); lua_pushcfunction(lua_L, &llua_conky_parse);
lua_setglobal(lua_L, "conky_parse"); lua_setglobal(lua_L, "conky_parse");
#if defined(X11) && defined(LUA_EXTRAS)
/* register tolua++ user types */
tolua_open(lua_L);
tolua_usertype(lua_L, "Drawable");
tolua_usertype(lua_L, "Visual");
tolua_usertype(lua_L, "Display");
#endif /* X11 */
} }
void llua_load(const char *script) void llua_load(const char *script)
@ -118,9 +130,9 @@ void llua_load(const char *script)
/* /*
llua_do_call does a flexible call to any Lua function llua_do_call does a flexible call to any Lua function
string: <function> [par1] [par2...] string: <function> [par1] [par2...]
retc: the number of return values expected retc: the number of return values expected
*/ */
char *llua_do_call(const char *string, int retc) char *llua_do_call(const char *string, int retc)
{ {
static char func[64]; static char func[64];
@ -375,62 +387,9 @@ void llua_set_long(const char *key, long value)
lua_setfield(lua_L, -2, key); lua_setfield(lua_L, -2, key);
} }
/* this function mostly copied from tolua++ source so that we could play nice
* with tolua++ libs. tolua++ is provided 'as is'
*/
void llua_set_userdata(const char *key, const char *type, void *value) void llua_set_userdata(const char *key, const char *type, void *value)
{ {
if (value == NULL) { tolua_pushusertype(lua_L, value, type);
lua_pushnil(lua_L);
} else {
luaL_getmetatable(lua_L, type);
lua_pushstring(lua_L,"tolua_ubox");
lua_rawget(lua_L,-2); /* stack: mt ubox */
if (lua_isnil(lua_L, -1)) {
lua_pop(lua_L, 1);
lua_pushstring(lua_L, "tolua_ubox");
lua_rawget(lua_L, LUA_REGISTRYINDEX);
}
lua_pushlightuserdata(lua_L,value);
lua_rawget(lua_L,-2); /* stack: mt ubox ubox[u] */
if (lua_isnil(lua_L,-1)) {
lua_pop(lua_L,1); /* stack: mt ubox */
lua_pushlightuserdata(lua_L,value);
*(void**)lua_newuserdata(lua_L,sizeof(void *)) = value; /* stack: mt ubox u newud */
lua_pushvalue(lua_L,-1); /* stack: mt ubox u newud newud */
lua_insert(lua_L,-4); /* stack: mt newud ubox u newud */
lua_rawset(lua_L,-3); /* stack: mt newud ubox */
lua_pop(lua_L,1); /* stack: mt newud */
/*luaL_getmetatable(lua_L,type);*/
lua_pushvalue(lua_L, -2); /* stack: mt newud mt */
lua_setmetatable(lua_L,-2); /* stack: mt newud */
} else {
/* check the need of updating the metatable to a more specialized class */
lua_insert(lua_L,-2); /* stack: mt ubox[u] ubox */
lua_pop(lua_L,1); /* stack: mt ubox[u] */
lua_pushstring(lua_L,"tolua_super");
lua_rawget(lua_L,LUA_REGISTRYINDEX); /* stack: mt ubox[u] super */
lua_getmetatable(lua_L,-2); /* stack: mt ubox[u] super mt */
lua_rawget(lua_L,-2); /* stack: mt ubox[u] super super[mt] */
if (lua_istable(lua_L,-1)) {
lua_pushstring(lua_L,type); /* stack: mt ubox[u] super super[mt] type */
lua_rawget(lua_L,-2); /* stack: mt ubox[u] super super[mt] flag */
if (lua_toboolean(lua_L,-1) == 1) {
/* if true */
lua_pop(lua_L,3); /* mt ubox[u]*/
lua_remove(lua_L, -2);
return;
}
}
/* type represents a more specilized type */
/*luaL_getmetatable(lua_L,type); // stack: mt ubox[u] super super[mt] flag mt */
lua_pushvalue(lua_L, -5); /* stack: mt ubox[u] super super[mt] flag mt */
lua_setmetatable(lua_L,-5); /* stack: mt ubox[u] super super[mt] flag */
lua_pop(lua_L,3); /* stack: mt ubox[u] */
}
lua_remove(lua_L, -2); /* stack: ubox[u]*/
}
lua_setfield(lua_L, -2, key); lua_setfield(lua_L, -2, key);
} }
@ -440,9 +399,11 @@ void llua_setup_window_table(int text_start_x, int text_start_y, int text_width,
lua_newtable(lua_L); lua_newtable(lua_L);
if (output_methods & TO_X) { if (output_methods & TO_X) {
#ifdef LUA_EXTRAS
llua_set_userdata("drawable", "Drawable", (void*)&window.drawable); llua_set_userdata("drawable", "Drawable", (void*)&window.drawable);
llua_set_userdata("visual", "Visual", window.visual); llua_set_userdata("visual", "Visual", window.visual);
llua_set_userdata("display", "Display", display); llua_set_userdata("display", "Display", display);
#endif /* LUA_EXTRAS */
llua_set_long("width", window.width); llua_set_long("width", window.width);