diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-07-08 17:08:49 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-07-08 17:08:49 (GMT) |
commit | 79bbb94d411dcef966403e2f33710fdb3aa2b528 (patch) | |
tree | 03b9410b98794b0d0a98a387185be5645ef0696e /src/FbTk | |
parent | 429ba7977a56e9cadf8f745d0f8908a189a830da (diff) | |
download | fluxbox_pavel-79bbb94d411dcef966403e2f33710fdb3aa2b528.zip fluxbox_pavel-79bbb94d411dcef966403e2f33710fdb3aa2b528.tar.bz2 |
Small optimization of the newindexDeny{Write,Modify} functions
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/LuaUtil.cc | 23 |
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 | ||
28 | namespace FbTk { | ||
29 | |||
28 | namespace { | 30 | namespace { |
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 | ||
58 | namespace 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(®isterNewindexes); | ||
74 | } // anonymous namespace | ||
59 | 75 | ||
60 | Lua::InitFunctions Lua::s_init_functions; | 76 | Lua::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); |