aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/LResource.hh
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-06-05 12:27:13 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-11-01 09:52:46 (GMT)
commitfc21fd822e527dbd918c6565e0e2cea82b0466f4 (patch)
treeb658bf437fafb80d39986c77caebcaf608761964 /src/FbTk/LResource.hh
parente3fabc4cd47ac5479bca421a4d7b79c0c2d9e120 (diff)
downloadfluxbox_pavel-fc21fd822e527dbd918c6565e0e2cea82b0466f4.zip
fluxbox_pavel-fc21fd822e527dbd918c6565e0e2cea82b0466f4.tar.bz2
A rough version of resource implementation in lua
I added a new class, LResourceManager, which should handle loading and saving of resources like the old ResourceManager, only it does that with the help of lua. I moved the common features of the two managers (interface + a few functions) to a common base class ResourceManager_base. I augmented the Resource_base class with two new functions (setFromLua and pushToLua) which are used by the lua RM instead of getString and setFromString. Parts of the new RM are written in lua. To avoid loading scripts from a file at runtime I decided to link compiled lua code straight into the executable. For this purpose I created a small script which converts a binary file into a declaration of a C array of bytes.
Diffstat (limited to 'src/FbTk/LResource.hh')
-rw-r--r--src/FbTk/LResource.hh59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/FbTk/LResource.hh b/src/FbTk/LResource.hh
new file mode 100644
index 0000000..897575b
--- /dev/null
+++ b/src/FbTk/LResource.hh
@@ -0,0 +1,59 @@
1// LResource: Fluxbox Resource implementation in lua
2// Copyright (C) 2011 Pavel Labath
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22#ifndef FBTK_LRESOURCE_HH
23#define FBTK_LRESOURCE_HH
24
25#include <cassert>
26#include <list>
27#include <memory>
28#include <string>
29
30#include "Resource.hh"
31
32namespace lua {
33 class state;
34}
35
36namespace FbTk {
37
38class LResourceManager: public ResourceManager_base {
39public:
40 static void initState(lua::state &l);
41
42 LResourceManager(lua::state &l, const std::string &root);
43 virtual bool save(const char *filename, const char *);
44 virtual void addResource(Resource_base &r);
45 virtual void removeResource(Resource_base &r);
46 Resource_base *findResource(const std::string &resname);
47 const Resource_base *findResource(const std::string &resname) const;
48
49private:
50 typedef std::list<Resource_base *> ResourceList;
51
52 ResourceList m_resourcelist;
53 lua::state *m_l;
54 std::string m_root;
55};
56
57} // end namespace FbTk
58
59#endif // FBTK_LRESOURCE_HH