aboutsummaryrefslogtreecommitdiff
path: root/src/FbCommands.cc
diff options
context:
space:
mode:
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 a3a0c27..9f3acdc 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"
@@ -622,4 +623,71 @@ void ClientPatternTestCmd::execute() {
622} 623}
623 624
624 625
626REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(lua, LuaCmd, void);
627
628namespace {
629 const char LuaCmds[] = "FbCommands::LuaCmd";
630}
631
632LuaCmd::LuaCmd(const std::string &chunk) {
633 lua::state &l = Fluxbox::instance()->lua();
634 l.checkstack(1);
635 l.loadstring(chunk);
636 init(l);
637}
638
639LuaCmd::LuaCmd(lua::state &l) {
640 lua::stack_sentry s(l, -1);
641 if(l.isstring(-1)) {
642 const std::string &str = l.tostring(-1);
643 l.pop();
644 l.loadstring(str);
645 }
646 init(l);
647}
648
649void LuaCmd::init(lua::state &l) {
650 lua::stack_sentry s(l, -1);
651 l.checkstack(2);
652
653 l.rawgetfield(lua::REGISTRYINDEX, LuaCmds); {
654 if(l.isnil(-1)) {
655 l.pop();
656 l.newtable();
657
658 l.pushvalue(-1);
659 l.rawsetfield(lua::REGISTRYINDEX, LuaCmds);
660 }
661
662 l.pushvalue(-2);
663 m_ref = l.ref(-2);
664 } l.pop();
665
666 l.pop();
667}
668
669LuaCmd::~LuaCmd() {
670 lua::state &l = Fluxbox::instance()->lua();
671 l.checkstack(1);
672 lua::stack_sentry s(l);
673
674 l.rawgetfield(lua::REGISTRYINDEX, LuaCmds); {
675 l.unref(-1, m_ref);
676 } l.pop();
677}
678
679void LuaCmd::execute() {
680 lua::state &l = Fluxbox::instance()->lua();
681 l.checkstack(1);
682 lua::stack_sentry s(l);
683
684 l.rawgetfield(lua::REGISTRYINDEX, LuaCmds); {
685 assert(l.istable(-1));
686
687 l.rawgeti(-1, m_ref); {
688 assert(! l.isnil(-1));
689 } l.call(0, 0);
690 } l.pop();
691}
692
625} // end namespace FbCommands 693} // end namespace FbCommands