diff options
Diffstat (limited to 'src/FbCommands.cc')
-rw-r--r-- | src/FbCommands.cc | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/FbCommands.cc b/src/FbCommands.cc index fa4c823..42ea669 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" |
@@ -554,4 +555,71 @@ void DeiconifyCmd::execute() { | |||
554 | }; | 555 | }; |
555 | } | 556 | } |
556 | 557 | ||
558 | REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(lua, LuaCmd, void); | ||
559 | |||
560 | namespace { | ||
561 | const char LuaCmds[] = "FbCommands::LuaCmd"; | ||
562 | } | ||
563 | |||
564 | LuaCmd::LuaCmd(const std::string &chunk) { | ||
565 | lua::state &l = Fluxbox::instance()->lua(); | ||
566 | l.checkstack(1); | ||
567 | l.loadstring(chunk); | ||
568 | init(l); | ||
569 | } | ||
570 | |||
571 | LuaCmd::LuaCmd(lua::state &l) { | ||
572 | lua::stack_sentry s(l, -1); | ||
573 | if(l.isstring(-1)) { | ||
574 | const std::string &str = l.tostring(-1); | ||
575 | l.pop(); | ||
576 | l.loadstring(str); | ||
577 | } | ||
578 | init(l); | ||
579 | } | ||
580 | |||
581 | void LuaCmd::init(lua::state &l) { | ||
582 | lua::stack_sentry s(l, -1); | ||
583 | l.checkstack(2); | ||
584 | |||
585 | 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 | m_ref = l.ref(-2); | ||
596 | } l.pop(); | ||
597 | |||
598 | l.pop(); | ||
599 | } | ||
600 | |||
601 | LuaCmd::~LuaCmd() { | ||
602 | lua::state &l = Fluxbox::instance()->lua(); | ||
603 | l.checkstack(1); | ||
604 | lua::stack_sentry s(l); | ||
605 | |||
606 | l.rawgetfield(lua::REGISTRYINDEX, LuaCmds); { | ||
607 | l.unref(-1, m_ref); | ||
608 | } l.pop(); | ||
609 | } | ||
610 | |||
611 | void LuaCmd::execute() { | ||
612 | lua::state &l = Fluxbox::instance()->lua(); | ||
613 | l.checkstack(1); | ||
614 | lua::stack_sentry s(l); | ||
615 | |||
616 | l.rawgetfield(lua::REGISTRYINDEX, LuaCmds); { | ||
617 | assert(l.istable(-1)); | ||
618 | |||
619 | l.rawgeti(-1, m_ref); { | ||
620 | assert(! l.isnil(-1)); | ||
621 | } l.call(0, 0); | ||
622 | } l.pop(); | ||
623 | } | ||
624 | |||
557 | } // end namespace FbCommands | 625 | } // end namespace FbCommands |