changeset 2197:ef11ba400848

Overlay info with lua
author Klaus Ethgen <Klaus@Ethgen.de>
date Thu, 04 Mar 2010 21:05:13 +0100
parents 7a9bff812ba3
children a51edfa978a8
files src/glua.h src/image-overlay.c src/lua.c src/lua.h src/main.c
diffstat 5 files changed, 77 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/glua.h	Thu Mar 04 21:05:13 2010 +0100
@@ -0,0 +1,32 @@
+/** \file
+ * \short LUA implementation
+ * \author Klaus Ethgen <Klaus@Ethgen.de>
+ */
+
+/*
+ *  This file is a part of Geeqie project (http://geeqie.sourceforge.net/).
+ *  Copyright (C) 2008 - 2010 The Geeqie Team
+ *
+ *  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.
+ */
+
+#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: */
--- a/src/image-overlay.c	Sat Jun 27 22:38:09 2009 +0100
+++ b/src/image-overlay.c	Thu Mar 04 21:05:13 2010 +0100
@@ -25,6 +25,7 @@
 #include "pixbuf_util.h"
 #include "ui_fileops.h"
 #include "image-load.h"
+#include "glua.h"
 
 /*
  *----------------------------------------------------------------------------
@@ -318,6 +319,17 @@
 			{
 			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));
--- a/src/lua.c	Sat Jun 27 22:38:09 2009 +0100
+++ b/src/lua.c	Thu Mar 04 21:05:13 2010 +0100
@@ -24,6 +24,12 @@
 
 #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 @@
 	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: */
--- a/src/lua.h	Sat Jun 27 22:38:09 2009 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-/** \file
- * \short LUA implementation
- * \author Klaus Ethgen <Klaus@Ethgen.de>
- */
-
-/*
- *  This file is a part of Geeqie project (http://geeqie.sourceforge.net/).
- *  Copyright (C) 2008 - 2010 The Geeqie Team
- *
- *  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.
- */
-
-#ifndef __LUA_H
-#define __LUA_H
-
-#ifdef HAVE_LUA
-
-void lua_init(void);
-
-#endif
-#endif
-/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/main.c	Sat Jun 27 22:38:09 2009 +0100
+++ b/src/main.c	Thu Mar 04 21:05:13 2010 +0100
@@ -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