Overlay info with lua
authorKlaus Ethgen <Klaus@Ethgen.de>
Thu, 4 Mar 2010 20:05:13 +0000 (21:05 +0100)
committerKlaus Ethgen <Klaus@Ethgen.de>
Thu, 23 Dec 2010 17:12:45 +0000 (18:12 +0100)
src/glua.h [moved from src/lua.h with 91% similarity]
src/image-overlay.c
src/lua.c
src/main.c

similarity index 91%
rename from src/lua.h
rename to src/glua.h
index b24776d..d72b47b 100644 (file)
--- a/src/lua.h
  *  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: */
index 54d11eb..e2f80b5 100644 (file)
@@ -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));
index a711b27..64cb042 100644 (file)
--- a/src/lua.c
+++ b/src/lua.c
 
 #include <lua.h>
 #include <lauxlib.h>
+#include <lualib.h>
+
+#include <stdio.h>
+#include <glib.h>
+
+#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: */
index b54ac30..7ad93a2 100644 (file)
@@ -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