aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/LResource.cc
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-08-01 15:33:40 (GMT)
committerPavel Labath <pavelo@centrum.sk>2013-02-18 21:04:25 (GMT)
commit552facbbfc3f04ee4bcadaec2d7886120b301617 (patch)
treec8281fa5855b19a1fb00954aabe8979d68f8f7c9 /src/FbTk/LResource.cc
parent14e9ec143f39a8a5c0a5dd05cf8445422f14e534 (diff)
downloadfluxbox_pavel-552facbbfc3f04ee4bcadaec2d7886120b301617.zip
fluxbox_pavel-552facbbfc3f04ee4bcadaec2d7886120b301617.tar.bz2
Refactoring: move details if init file loading into LResourceManager
Diffstat (limited to 'src/FbTk/LResource.cc')
-rw-r--r--src/FbTk/LResource.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/FbTk/LResource.cc b/src/FbTk/LResource.cc
index 0909520..31362bd 100644
--- a/src/FbTk/LResource.cc
+++ b/src/FbTk/LResource.cc
@@ -24,6 +24,7 @@
24 24
25#include "LResource.hh" 25#include "LResource.hh"
26 26
27#include "I18n.hh"
27#include "LuaUtil.hh" 28#include "LuaUtil.hh"
28#include "Resource.hh" 29#include "Resource.hh"
29 30
@@ -105,10 +106,43 @@ LResourceManager::LResourceManager(const std::string &root, Lua &l)
105 setLua(l); 106 setLua(l);
106} 107}
107 108
109void LResourceManager::load(const std::string &filename, const std::string &fallback) {
110 _FB_USES_NLS;
111 m_l->checkstack(1);
112 lua::stack_sentry s(*m_l);
113
114 m_filename = filename;
115
116 try {
117 m_l->loadfile(filename.c_str());
118 m_l->call(0, 0);
119 }
120 catch(lua::exception &e) {
121 std::cerr << _FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database",
122 "Failed trying to read rc file") << ":" << filename << std::endl;
123 std::cerr << "Fluxbox: " << e.what() << std::endl;
124 std::cerr << _FB_CONSOLETEXT(Fluxbox, CantLoadRCFileTrying, "Retrying with",
125 "Retrying rc file loading with (the following file)")
126 << ": " << fallback << std::endl;
127 try {
128 m_l->loadfile(fallback.c_str());
129 m_l->call(0, 0);
130 }
131 catch(lua::exception &e) {
132 std::cerr << _FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database", "")
133 << ": " << fallback << std::endl;
134 std::cerr << "Fluxbox: " << e.what() << std::endl;
135 }
136 }
137}
138
108bool LResourceManager::save(const char *filename, const char *) { 139bool LResourceManager::save(const char *filename, const char *) {
109 m_l->checkstack(3); 140 m_l->checkstack(3);
110 lua::stack_sentry s(*m_l); 141 lua::stack_sentry s(*m_l);
111 142
143 if(filename == NULL)
144 filename = m_filename.c_str();
145
112 m_l->getfield(lua::REGISTRYINDEX, dump_resources); 146 m_l->getfield(lua::REGISTRYINDEX, dump_resources);
113 m_l->getfield(lua::GLOBALSINDEX, m_root.c_str()); 147 m_l->getfield(lua::GLOBALSINDEX, m_root.c_str());
114 m_l->pushstring(filename); 148 m_l->pushstring(filename);