aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-07-08 13:35:42 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-11-01 09:57:21 (GMT)
commitdbc29ae953ab73b9cdd2a13dbe17a1eb0a8c863a (patch)
tree0ad775057cef0499f1e02d0946ecb2ac52cf3eed
parentb3bd3805961c05776c7f398ce98082effebd8ca2 (diff)
downloadfluxbox_pavel-dbc29ae953ab73b9cdd2a13dbe17a1eb0a8c863a.zip
fluxbox_pavel-dbc29ae953ab73b9cdd2a13dbe17a1eb0a8c863a.tar.bz2
use Lua::registerInitFunction to simplify some parts of code
-rw-r--r--src/FbCommands.cc19
-rw-r--r--src/FbTk/LResource.cc47
-rw-r--r--src/FbTk/LResource.hh11
-rw-r--r--src/MenuCreator.cc1
-rw-r--r--src/Screen.cc2
-rw-r--r--src/fluxbox.cc3
-rw-r--r--src/fluxbox.hh4
7 files changed, 42 insertions, 45 deletions
diff --git a/src/FbCommands.cc b/src/FbCommands.cc
index 3ece374..d52084e 100644
--- a/src/FbCommands.cc
+++ b/src/FbCommands.cc
@@ -31,7 +31,7 @@
31#include "MenuCreator.hh" 31#include "MenuCreator.hh"
32 32
33#include "FbTk/I18n.hh" 33#include "FbTk/I18n.hh"
34#include "FbTk/Luamm.hh" 34#include "FbTk/LuaUtil.hh"
35#include "FbTk/Theme.hh" 35#include "FbTk/Theme.hh"
36#include "FbTk/Menu.hh" 36#include "FbTk/Menu.hh"
37#include "FbTk/CommandParser.hh" 37#include "FbTk/CommandParser.hh"
@@ -559,6 +559,15 @@ REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(lua, LuaCmd, void);
559 559
560namespace { 560namespace {
561 const char LuaCmds[] = "FbCommands::LuaCmd"; 561 const char LuaCmds[] = "FbCommands::LuaCmd";
562
563 void initLuaCmds(FbTk::Lua &l) {
564 l.checkstack(1);
565
566 l.newtable();
567 l.rawsetfield(lua::REGISTRYINDEX, LuaCmds);
568 }
569
570 FbTk::Lua::RegisterInitFunction register_init_lua_cmds(&initLuaCmds);
562} 571}
563 572
564LuaCmd::LuaCmd(const std::string &chunk) { 573LuaCmd::LuaCmd(const std::string &chunk) {
@@ -583,14 +592,6 @@ void LuaCmd::init(lua::state &l) {
583 l.checkstack(2); 592 l.checkstack(2);
584 593
585 l.rawgetfield(lua::REGISTRYINDEX, LuaCmds); { 594 l.rawgetfield(lua::REGISTRYINDEX, LuaCmds); {
586 if(l.isnil(-1)) {
587 l.pop();
588 l.newtable();
589
590 l.pushvalue(-1);
591 l.rawsetfield(lua::REGISTRYINDEX, LuaCmds);
592 }
593
594 l.pushvalue(-2); 595 l.pushvalue(-2);
595 m_ref = l.ref(-2); 596 m_ref = l.ref(-2);
596 } l.pop(); 597 } l.pop();
diff --git a/src/FbTk/LResource.cc b/src/FbTk/LResource.cc
index b91f0d8..6671b89 100644
--- a/src/FbTk/LResource.cc
+++ b/src/FbTk/LResource.cc
@@ -24,8 +24,8 @@
24 24
25#include "LResource.hh" 25#include "LResource.hh"
26 26
27#include "LuaUtil.hh"
27#include "Resource.hh" 28#include "Resource.hh"
28#include "Luamm.hh"
29 29
30extern const char LResourceHelper[]; 30extern const char LResourceHelper[];
31extern const unsigned int LResourceHelper_size; 31extern const unsigned int LResourceHelper_size;
@@ -61,30 +61,32 @@ namespace {
61 61
62 return 0; 62 return 0;
63 } 63 }
64}
65 64
66void LResourceManager::initState(lua::state &l) { 65 void initState(Lua &l) {
67 l.checkstack(6); 66 l.checkstack(6);
68 lua::stack_sentry s(l); 67 lua::stack_sentry s(l);
69 68
70 l.loadstring(LResourceHelper, LResourceHelper_size); 69 l.loadstring(LResourceHelper, LResourceHelper_size);
71 l.pushfunction(&readResource); 70 l.pushfunction(&readResource);
72 l.pushfunction(&writeResource); 71 l.pushfunction(&writeResource);
73 l.newtable(); {
74 l.newtable(); { 72 l.newtable(); {
75 l.pushvalue(-2); 73 l.newtable(); {
76 l.setfield(-2, "__metatable"); 74 l.pushvalue(-2);
77 } l.setfield(lua::REGISTRYINDEX, resource_metatable); 75 l.setfield(-2, "__metatable");
76 } l.setfield(lua::REGISTRYINDEX, resource_metatable);
77 }
78 l.call(3, 3);
79 l.setfield(lua::REGISTRYINDEX, dump_resources);
80 l.setfield(lua::REGISTRYINDEX, register_resource);
81 l.setfield(lua::REGISTRYINDEX, make_root);
78 } 82 }
79 l.call(3, 3); 83
80 l.setfield(lua::REGISTRYINDEX, dump_resources); 84 Lua::RegisterInitFunction register_init_state(&initState);
81 l.setfield(lua::REGISTRYINDEX, register_resource); 85
82 l.setfield(lua::REGISTRYINDEX, make_root); 86} // anonymous namespace
83}
84 87
85void LResourceManager::convert(ResourceManager &old, const std::string &new_file) { 88void LResourceManager::convert(ResourceManager &old, const std::string &new_file) {
86 lua::state l; 89 Lua l;
87 initState(l);
88 90
89 LResourceManager new_rm(old.root(), l); 91 LResourceManager new_rm(old.root(), l);
90 for(ResourceList::const_iterator i = old.begin(); i != old.end(); ++i) { 92 for(ResourceList::const_iterator i = old.begin(); i != old.end(); ++i) {
@@ -98,17 +100,12 @@ void LResourceManager::convert(ResourceManager &old, const std::string &new_file
98 new_rm.save(new_file.c_str(), NULL); 100 new_rm.save(new_file.c_str(), NULL);
99} 101}
100 102
101LResourceManager::LResourceManager(const std::string &root, lua::state &l) 103LResourceManager::LResourceManager(const std::string &root, Lua &l)
102 : ResourceManager_base(root), m_l(&l) { 104 : ResourceManager_base(root), m_l(&l) {
103 l.checkstack(2); 105 l.checkstack(2);
104 lua::stack_sentry s(l); 106 lua::stack_sentry s(l);
105 107
106 l.getfield(lua::REGISTRYINDEX, make_root); 108 l.getfield(lua::REGISTRYINDEX, make_root);
107 if(l.isnil(-1)) {
108 l.pop();
109 initState(l);
110 l.getfield(lua::REGISTRYINDEX, make_root);
111 }
112 l.pushstring(root); 109 l.pushstring(root);
113 l.call(1, 0); 110 l.call(1, 0);
114} 111}
diff --git a/src/FbTk/LResource.hh b/src/FbTk/LResource.hh
index 1125707..1567269 100644
--- a/src/FbTk/LResource.hh
+++ b/src/FbTk/LResource.hh
@@ -29,25 +29,22 @@
29 29
30#include "Resource.hh" 30#include "Resource.hh"
31 31
32namespace lua {
33 class state;
34}
35
36namespace FbTk { 32namespace FbTk {
37 33
34class Lua;
35
38class LResourceManager: public ResourceManager_base { 36class LResourceManager: public ResourceManager_base {
39public: 37public:
40 static void initState(lua::state &l);
41 static void convert(ResourceManager &old, const std::string &new_file); 38 static void convert(ResourceManager &old, const std::string &new_file);
42 39
43 LResourceManager(const std::string &root, lua::state &l); 40 LResourceManager(const std::string &root, Lua &l);
44 virtual bool save(const char *filename, const char *); 41 virtual bool save(const char *filename, const char *);
45 virtual void addResource(Resource_base &r); 42 virtual void addResource(Resource_base &r);
46 virtual void removeResource(Resource_base &r); 43 virtual void removeResource(Resource_base &r);
47 44
48private: 45private:
49 46
50 lua::state *m_l; 47 Lua *m_l;
51}; 48};
52 49
53} // end namespace FbTk 50} // end namespace FbTk
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc
index ea45487..406d9e5 100644
--- a/src/MenuCreator.cc
+++ b/src/MenuCreator.cc
@@ -43,6 +43,7 @@
43#include "RootCmdMenuItem.hh" 43#include "RootCmdMenuItem.hh"
44 44
45#include "FbTk/I18n.hh" 45#include "FbTk/I18n.hh"
46#include "FbTk/LuaUtil.hh"
46#include "FbTk/MultiButtonMenuItem.hh" 47#include "FbTk/MultiButtonMenuItem.hh"
47#include "FbTk/BoolMenuItem.hh" 48#include "FbTk/BoolMenuItem.hh"
48#include "FbTk/RefCount.hh" 49#include "FbTk/RefCount.hh"
diff --git a/src/Screen.cc b/src/Screen.cc
index 215d48b..376c3f5 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -73,7 +73,7 @@
73#include "FbTk/STLUtil.hh" 73#include "FbTk/STLUtil.hh"
74#include "FbTk/KeyUtil.hh" 74#include "FbTk/KeyUtil.hh"
75#include "FbTk/Util.hh" 75#include "FbTk/Util.hh"
76#include "FbTk/Luamm.hh" 76#include "FbTk/LuaUtil.hh"
77 77
78//use GNU extensions 78//use GNU extensions
79#ifndef _GNU_SOURCE 79#ifndef _GNU_SOURCE
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index 912d61f..5a10c7b 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -43,6 +43,7 @@
43#include "FbTk/FileUtil.hh" 43#include "FbTk/FileUtil.hh"
44#include "FbTk/ImageControl.hh" 44#include "FbTk/ImageControl.hh"
45#include "FbTk/EventManager.hh" 45#include "FbTk/EventManager.hh"
46#include "FbTk/LuaUtil.hh"
46#include "FbTk/StringUtil.hh" 47#include "FbTk/StringUtil.hh"
47#include "FbTk/Util.hh" 48#include "FbTk/Util.hh"
48#include "FbTk/LResource.hh" 49#include "FbTk/LResource.hh"
@@ -227,7 +228,7 @@ Fluxbox::Fluxbox(int argc, char **argv,
227 const std::string& dpy_name, 228 const std::string& dpy_name,
228 const std::string& rc_path, const std::string& rc_filename, bool xsync) 229 const std::string& rc_path, const std::string& rc_filename, bool xsync)
229 : FbTk::App(dpy_name.c_str()), 230 : FbTk::App(dpy_name.c_str()),
230 m_l(new lua::state()), 231 m_l(new Lua),
231 m_fbatoms(FbAtoms::instance()), 232 m_fbatoms(FbAtoms::instance()),
232 m_resourcemanager("session", *m_l), 233 m_resourcemanager("session", *m_l),
233 234
diff --git a/src/fluxbox.hh b/src/fluxbox.hh
index e027660..c241fb7 100644
--- a/src/fluxbox.hh
+++ b/src/fluxbox.hh
@@ -173,7 +173,7 @@ public:
173 /// get screen from number 173 /// get screen from number
174 BScreen *findScreen(int num); 174 BScreen *findScreen(int num);
175 175
176 lua::state &lua() { return *m_l; } 176 FbTk::Lua& lua() { return *m_l; }
177 177
178 typedef std::list<BScreen *> ScreenList; 178 typedef std::list<BScreen *> ScreenList;
179 const ScreenList screenList() const { return m_screen_list; } 179 const ScreenList screenList() const { return m_screen_list; }
@@ -226,7 +226,7 @@ private:
226 /// Called when a window layer changes 226 /// Called when a window layer changes
227 void windowLayerChanged(FluxboxWindow &win); 227 void windowLayerChanged(FluxboxWindow &win);
228 228
229 std::auto_ptr<lua::state> m_l; 229 std::auto_ptr<FbTk::Lua> m_l;
230 std::auto_ptr<FbAtoms> m_fbatoms; 230 std::auto_ptr<FbAtoms> m_fbatoms;
231 231
232 FbTk::LResourceManager m_resourcemanager; 232 FbTk::LResourceManager m_resourcemanager;