From fd902cc2c9c6c06a0d6ea30fd00652814af91013 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Tue, 9 Aug 2011 10:05:23 +0200 Subject: Add a :clear() method for removing keybindings --- src/Keys.cc | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Keys.cc b/src/Keys.cc index 92b8718..4d366e5 100644 --- a/src/Keys.cc +++ b/src/Keys.cc @@ -149,6 +149,7 @@ public: static int newKeyMode(lua::state *l); static int index(lua::state *l); static int newindex(lua::state *l); + static int clear(lua::state *l); bool equalExact(const RefKey &x) { return type == x->type && key == x->key && context == x->context @@ -196,8 +197,7 @@ public: static FbTk::Lua::RegisterInitFunction registerInitKeys; }; -int Keys::t_key::newindex(lua::state *l) -{ +int Keys::t_key::newindex(lua::state *l) { l->checkstack(2); try { @@ -269,6 +269,8 @@ int Keys::t_key::index(lua::state *l) { if(str == "activate") l->pushfunction(&setKeyModeWrapper); + else if(str == "clear") + l->pushfunction(&clear); else { vector val; FbTk::StringUtil::stringtok(val, str.c_str()); @@ -293,6 +295,21 @@ int Keys::t_key::index(lua::state *l) { return 1; } +int Keys::t_key::clear(lua::state *l) { + try { + l->checkargno(1); + const RefKey &k = *l->checkudata(1, keymode_metatable); + + k->keylist.clear(); + k->m_command.reset(); + } + catch(std::runtime_error &e) { + cerr << "clear: " << e.what() << endl; + } + return 0; + +} + void Keys::t_key::initKeys(FbTk::Lua &l) { l.checkstack(3); lua::stack_sentry s(l); -- cgit v0.11.2