2 * \short LUA implementation
3 * \author Klaus Ethgen <Klaus@Ethgen.de>
7 * This file is a part of Geeqie project (http://geeqie.sourceforge.net/).
8 * Copyright (C) 2008 - 2010 The Geeqie Team
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
34 #include "ui_fileops.h"
37 static lua_State *L; /** The LUA object needed for all operations (NOTE: That is
38 * a upper-case variable to match the documentation!) */
40 static FileData *lua_check_image(lua_State *L, int index)
43 luaL_checktype(L, index, LUA_TUSERDATA);
44 fd = (FileData **)luaL_checkudata(L, index, "Image");
45 if (fd == NULL) luaL_typerror(L, index, "Image");
49 /* Interface for EXIF data */
50 static int lua_exif_get_datum(lua_State *L)
57 fd = lua_check_image(L, 1);
58 key = luaL_checkstring(L, 2);
59 if (key == (gchar*)NULL || key[0] == '\0')
64 exif = exif_read_fd(fd);
70 value = exif_get_data_as_text(exif, key);
71 lua_pushstring(L, value);
76 * \brief Initialize the lua interpreter.
81 luaL_openlibs(L); /* Open all libraries for lua programms */
83 /* Now create custom methodes to do something */
84 static const luaL_Reg exif_methods[] = {
85 {"get_datum", lua_exif_get_datum},
88 luaL_register(L, "Exif", exif_methods);
92 * \brief Call a lua function to get a single value.
94 gchar *lua_callvalue(FileData *fd, const gchar *file, const gchar *function)
100 FileData **user_data;
102 user_data = (FileData **)lua_newuserdata(L, sizeof(FileData *));
103 luaL_newmetatable(L, "Image");
104 //luaL_getmetatable(L, "Image");
105 lua_setmetatable(L, -2);
106 lua_setglobal(L, "Image");
110 result = luaL_dostring(L, function);
114 dir = g_build_filename(get_rc_dir(), "lua", NULL);
115 path = g_build_filename(dir, file, NULL);
116 result = luaL_dofile(L, path);
123 data = g_strdup_printf("Error running lua script: %s", lua_tostring(L, -1));
126 data = g_strdup(lua_tostring(L, -1));
131 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */