Themes are now searched by desktop files.
[tagua/yd.git] / src / luaapi / loader.h
bloba98697dca3e9243f296579b4ce5012fafd914eb7
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef LUAAPI__LOADER_H
12 #define LUAAPI__LOADER_H
14 #include <map>
15 #include <vector>
16 #include <boost/variant.hpp>
17 #include <QDir>
18 #include <QImage>
19 #include "loader/image.h"
20 #include "luaapi/luavalue.h"
21 #include "option.h"
23 class lua_State;
24 class luaL_Reg;
26 namespace Loader {
27 class Context;
30 namespace LuaApi {
32 class RectLess {
33 public:
34 bool operator()(const QRect& a, const QRect& b) {
35 return a.x() != b.x() ? a.x() < b.x() :
36 a.y() != b.y() ? a.y() < b.y() :
37 a.width() != b.width() ? a.width() < b.width() :
38 a.height() < b.height();
42 typedef std::map<QRect, QImage, RectLess> ImageMap;
43 typedef boost::variant<QImage, ImageMap> ImageOrMap;
45 class Loader {
46 bool m_error;
47 QString m_error_string;
49 lua_State* m_state;
50 QDir m_curr_dir;
52 static const luaL_Reg lualibs[];
54 template<typename T> struct create_value_data;
55 template<typename T> static void retrieve(create_value_data<T>*, lua_State *l, int pos);
56 template<typename T> static int create_value_func(lua_State *l);
58 static int import_func(lua_State* l);
59 static int read_desktop_file(lua_State* l);
60 public:
61 Loader(::Loader::Context *ctx);
62 ~Loader();
64 lua_State* state() const { return m_state; }
65 bool runFile(const QString& file, bool set_dir = true);
67 template<typename T> T getValue(const QString& key, int size = 0,
68 const LuaValueMap* args = NULL, bool allow_nil = false);
70 bool error() { return m_error; }
71 void clearError() { m_error = false; }
72 QString errorString() { return m_error_string; }
74 QDir currDir() { return m_curr_dir; }
77 } //end namespace LuaApi
80 #endif // LUAAPI__LOADERAPI_H