From: Klaus Ethgen Date: Thu, 4 Mar 2010 20:05:13 +0000 (+0100) Subject: Overlay info with lua X-Git-Tag: v1.2~11^2~11 X-Git-Url: http://geeqie.org/cgi-bin/gitweb.cgi?p=geeqie.git;a=commitdiff_plain;h=ee7d5c882dd136b160c94359fb3182e49df0fbee Overlay info with lua --- diff --git a/src/lua.h b/src/glua.h similarity index 91% rename from src/lua.h rename to src/glua.h index b24776d7..d72b47bf 100644 --- a/src/lua.h +++ b/src/glua.h @@ -18,13 +18,15 @@ * more details. */ -#ifndef __LUA_H -#define __LUA_H +#ifndef __GLUA_H +#define __GLUA_H #ifdef HAVE_LUA void lua_init(void); +gchar *lua_callvalue(gchar *, gchar *); + #endif #endif /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ diff --git a/src/image-overlay.c b/src/image-overlay.c index 54d11ebe..e2f80b5c 100644 --- a/src/image-overlay.c +++ b/src/image-overlay.c @@ -25,6 +25,7 @@ #include "pixbuf_util.h" #include "ui_fileops.h" #include "image-load.h" +#include "glua.h" /* *---------------------------------------------------------------------------- @@ -318,6 +319,17 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v { data = metadata_read_string(imd->image_fd, COMMENT_KEY, METADATA_PLAIN); } +#ifdef HAVE_LUA + else if (strncmp(name, "lua/", 4) == 0) + { + gchar *tmp; + tmp = strchr(name+4, '/'); + if (!tmp) + break; + *tmp = '\0'; + data = lua_callvalue(name+4, tmp+1); + } +#endif else { data = g_strdup(g_hash_table_lookup(vars, name)); diff --git a/src/lua.c b/src/lua.c index a711b274..64cb0427 100644 --- a/src/lua.c +++ b/src/lua.c @@ -24,6 +24,12 @@ #include #include +#include + +#include +#include + +#include "glua.h" static lua_State *L; /** The LUA object needed for all operations (NOTE: That is * a upper-case variable to match the documentation!) */ @@ -37,5 +43,31 @@ void lua_init(void) luaL_openlibs(L); /* Open all libraries for lua programms */ } +/** + * \brief Call a lua function to get a single value. + */ +gchar *lua_callvalue(gchar *file, gchar *function) +{ + gint result; + gchar *data = NULL; + + if (file[0] == '\0') + { + result = luaL_dostring(L, function); + } + else + { + result = luaL_dofile(L, file); + } + + if (result) + { + data = g_strdup_printf("Error running lua script: %s", lua_tostring(L, -1)); + return data; + } + data = g_strdup(lua_tostring(L, -1)); + return data; +} + #endif /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ diff --git a/src/main.c b/src/main.c index b54ac300..7ad93a20 100644 --- a/src/main.c +++ b/src/main.c @@ -45,7 +45,7 @@ #include "exif.h" #include "histogram.h" #include "pixbuf_util.h" -#include "lua.h" +#include "glua.h" #ifdef HAVE_LIBCHAMPLAIN #ifdef HAVE_LIBCHAMPLAIN_GTK