Tentative MiniShogi implementation over move generator.
[tagua/yd.git] / src / luaapi / loader.h
blob270526d7e5d8b844ed1bea8ad34b9d8647227335
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
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;
25 class ThemeInfo;
27 namespace Loader {
28 class Context;
31 namespace LuaApi {
33 class RectLess {
34 public:
35 bool operator()(const QRect& a, const QRect& b) {
36 return a.x() != b.x() ? a.x() < b.x() :
37 a.y() != b.y() ? a.y() < b.y() :
38 a.width() != b.width() ? a.width() < b.width() :
39 a.height() < b.height();
43 typedef std::map<QRect, QImage, RectLess> ImageMap;
44 typedef boost::variant<QImage, ImageMap> ImageOrMap;
46 class Loader {
47 bool m_error;
48 QString m_error_string;
50 lua_State* m_state;
51 QDir m_curr_dir;
53 static const luaL_Reg lualibs[];
55 template<typename T> struct create_value_data;
56 template<typename T> static void retrieve(create_value_data<T>*, lua_State *l, int pos);
57 template<typename T> static int create_value_func(lua_State *l);
58 static int import_func(lua_State* l);
60 void initialize(::Loader::Context *ctx);
62 /**
63 * Add the theme table to the environment, with all theme metadata.
65 void addMetaData(const ThemeInfo& theme);
66 public:
67 Loader(::Loader::Context *ctx, const ThemeInfo& theme);
68 Loader();
70 ~Loader();
72 lua_State* state() const { return m_state; }
73 bool runFile(const QString& file, bool set_dir = true);
75 template<typename T> T getValue(const QString& key, int size = 0,
76 const LuaValueMap* args = NULL, bool allow_nil = false);
78 bool error() { return m_error; }
79 void clearError() { m_error = false; }
80 QString errorString() { return m_error_string; }
83 } //end namespace LuaApi
86 #endif // LUAAPI__LOADERAPI_H