aboutsummaryrefslogtreecommitdiff
path: root/src/FbCommands.cc
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-07-02 22:05:05 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-07-02 22:05:05 (GMT)
commit356f64a70206d4fcc828480bdd8ba99bda7f2fcb (patch)
tree45cecd018604ff6ed92110ccccb86e76f5a5446c /src/FbCommands.cc
parent4f1c55ab980262e218dbb5ab73497c61096c868a (diff)
downloadfluxbox_pavel-356f64a70206d4fcc828480bdd8ba99bda7f2fcb.zip
fluxbox_pavel-356f64a70206d4fcc828480bdd8ba99bda7f2fcb.tar.bz2
Add a new command which executes lua functions
Diffstat (limited to 'src/FbCommands.cc')
-rw-r--r--src/FbCommands.cc68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/FbCommands.cc b/src/FbCommands.cc
index d366164..0d7c1df 100644
--- a/src/FbCommands.cc
+++ b/src/FbCommands.cc
@@ -31,6 +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/Theme.hh" 35#include "FbTk/Theme.hh"
35#include "FbTk/Menu.hh" 36#include "FbTk/Menu.hh"
36#include "FbTk/CommandParser.hh" 37#include "FbTk/CommandParser.hh"
@@ -542,4 +543,71 @@ void DeiconifyCmd::execute() {
542 }; 543 };
543} 544}
544 545
546REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(lua, LuaCmd, void);
547
548namespace {
549 const char LuaCmds[] = "FbCommands::LuaCmd";
550}
551
552LuaCmd::LuaCmd(const std::string &chunk) {
553 lua::state &l = Fluxbox::instance()->lua();
554 l.checkstack(1);
555 l.loadstring(chunk);
556 init(l);
557}
558
559LuaCmd::LuaCmd(lua::state &l) {
560 lua::stack_sentry s(l, -1);
561 if(l.isstring(-1)) {
562 const std::string &str = l.tostring(-1);
563 l.pop();
564 l.loadstring(str);
565 }
566 init(l);
567}
568
569void LuaCmd::init(lua::state &l) {
570 lua::stack_sentry s(l, -1);
571 l.checkstack(2);
572
573 l.rawgetfield(lua::REGISTRYINDEX, LuaCmds); {
574 if(l.isnil(-1)) {
575 l.pop();
576 l.newtable();
577
578 l.pushvalue(-1);
579 l.rawsetfield(lua::REGISTRYINDEX, LuaCmds);
580 }
581
582 l.pushvalue(-2);
583 m_ref = l.ref(-2);
584 } l.pop();
585
586 l.pop();
587}
588
589LuaCmd::~LuaCmd() {
590 lua::state &l = Fluxbox::instance()->lua();
591 l.checkstack(1);
592 lua::stack_sentry s(l);
593
594 l.rawgetfield(lua::REGISTRYINDEX, LuaCmds); {
595 l.unref(-1, m_ref);
596 } l.pop();
597}
598
599void LuaCmd::execute() {
600 lua::state &l = Fluxbox::instance()->lua();
601 l.checkstack(1);
602 lua::stack_sentry s(l);
603
604 l.rawgetfield(lua::REGISTRYINDEX, LuaCmds); {
605 assert(l.istable(-1));
606
607 l.rawgeti(-1, m_ref); {
608 assert(! l.isnil(-1));
609 } l.call(0, 0);
610 } l.pop();
611}
612
545} // end namespace FbCommands 613} // end namespace FbCommands