aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-07-08 17:08:49 (GMT)
committerPavel Labath <pavelo@centrum.sk>2013-02-17 09:36:38 (GMT)
commit2d638f99c78b5abbde5c1506ef36fd6d4df6016c (patch)
treeb9d712d9238bcbace778e9c736aeb0f78a82c919 /src
parent084d43e7901efc121f48cb8bd838579ca916bef0 (diff)
downloadfluxbox_pavel-2d638f99c78b5abbde5c1506ef36fd6d4df6016c.zip
fluxbox_pavel-2d638f99c78b5abbde5c1506ef36fd6d4df6016c.tar.bz2
Small optimization of the newindexDeny{Write,Modify} functions
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/LuaUtil.cc23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/FbTk/LuaUtil.cc b/src/FbTk/LuaUtil.cc
index 456abac..7c24331 100644
--- a/src/FbTk/LuaUtil.cc
+++ b/src/FbTk/LuaUtil.cc
@@ -25,7 +25,12 @@
25 25
26#include "LuaUtil.hh" 26#include "LuaUtil.hh"
27 27
28namespace FbTk {
29
28namespace { 30namespace {
31 const char newindexDenyWriteName[] = "FbTk::Lua::newindexDenyWrite";
32 const char newindexDenyModifyName[] = "FbTk::Lua::newindexDenyModify";
33
29 int newindexDenyWrite(lua::state *l) { 34 int newindexDenyWrite(lua::state *l) {
30 if(l->isstring(-2)) 35 if(l->isstring(-2))
31 throw std::runtime_error("Cannot modify field '" + l->tostring(-2) + "'."); 36 throw std::runtime_error("Cannot modify field '" + l->tostring(-2) + "'.");
@@ -53,9 +58,20 @@ namespace {
53 58
54 return 0; 59 return 0;
55 } 60 }
56}
57 61
58namespace FbTk { 62 void registerNewindexes(Lua &l) {
63 l.checkstack(1);
64 lua::stack_sentry s(l);
65
66 l.pushfunction(&newindexDenyWrite);
67 l.rawsetfield(lua::REGISTRYINDEX, newindexDenyWriteName);
68
69 l.pushfunction(&newindexDenyModify);
70 l.rawsetfield(lua::REGISTRYINDEX, newindexDenyModifyName);
71 }
72
73 Lua::RegisterInitFunction register_newindexes(&registerNewindexes);
74} // anonymous namespace
59 75
60Lua::InitFunctions Lua::s_init_functions; 76Lua::InitFunctions Lua::s_init_functions;
61 77
@@ -81,7 +97,8 @@ void Lua::makeReadOnly(int index, bool only_existing_fields) {
81 } 97 }
82 } rawsetfield(-2, "__index"); 98 } rawsetfield(-2, "__index");
83 99
84 pushfunction(only_existing_fields ? &newindexDenyModify : &newindexDenyWrite); 100 rawgetfield(lua::REGISTRYINDEX,
101 only_existing_fields ? newindexDenyModifyName : newindexDenyWriteName);
85 rawsetfield(-2, "__newindex"); 102 rawsetfield(-2, "__newindex");
86 103
87 pushboolean(false); 104 pushboolean(false);