diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-05 12:27:13 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-06-15 23:07:49 (GMT) |
commit | de1e05cec6b26f6a7f398a9ea64f38fa0943f9c0 (patch) | |
tree | 6c5cb813d5cf4bad3c620fb42a2fb4236b9f9ec1 /src/FbTk/Resource.cc | |
parent | f7981d4a85985b4862af0036b7728f8543706374 (diff) | |
download | fluxbox_pavel-de1e05cec6b26f6a7f398a9ea64f38fa0943f9c0.zip fluxbox_pavel-de1e05cec6b26f6a7f398a9ea64f38fa0943f9c0.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/Resource.cc')
-rw-r--r-- | src/FbTk/Resource.cc | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/FbTk/Resource.cc b/src/FbTk/Resource.cc index 85e78da..fad4bf3 100644 --- a/src/FbTk/Resource.cc +++ b/src/FbTk/Resource.cc | |||
@@ -37,6 +37,24 @@ using std::string; | |||
37 | 37 | ||
38 | namespace FbTk { | 38 | namespace FbTk { |
39 | 39 | ||
40 | ResourceManager_base::~ResourceManager_base() { | ||
41 | } | ||
42 | |||
43 | string ResourceManager_base::resourceValue(const string &resname) const { | ||
44 | const Resource_base *res = findResource(resname); | ||
45 | if (res != 0) | ||
46 | return res->getString(); | ||
47 | |||
48 | return ""; | ||
49 | } | ||
50 | |||
51 | void ResourceManager_base::setResourceValue(const string &resname, const string &value) { | ||
52 | Resource_base *res = findResource(resname); | ||
53 | if (res != 0) | ||
54 | res->setFromString(value.c_str()); | ||
55 | |||
56 | } | ||
57 | |||
40 | ResourceManager::ResourceManager(const char *filename, bool lock_db) : | 58 | ResourceManager::ResourceManager(const char *filename, bool lock_db) : |
41 | m_db_lock(0), | 59 | m_db_lock(0), |
42 | m_database(0), | 60 | m_database(0), |
@@ -186,21 +204,6 @@ const Resource_base *ResourceManager::findResource(const string &resname) const | |||
186 | return 0; | 204 | return 0; |
187 | } | 205 | } |
188 | 206 | ||
189 | string ResourceManager::resourceValue(const string &resname) const { | ||
190 | const Resource_base *res = findResource(resname); | ||
191 | if (res != 0) | ||
192 | return res->getString(); | ||
193 | |||
194 | return ""; | ||
195 | } | ||
196 | |||
197 | void ResourceManager::setResourceValue(const string &resname, const string &value) { | ||
198 | Resource_base *res = findResource(resname); | ||
199 | if (res != 0) | ||
200 | res->setFromString(value.c_str()); | ||
201 | |||
202 | } | ||
203 | |||
204 | ResourceManager &ResourceManager::lock() { | 207 | ResourceManager &ResourceManager::lock() { |
205 | ++m_db_lock; | 208 | ++m_db_lock; |
206 | // if the lock was zero, then load the database | 209 | // if the lock was zero, then load the database |