aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-07-08 17:08:49 (GMT)
committerPaul Tagliamonte <paultag@fluxbox.org>2012-04-07 02:11:30 (GMT)
commitc9270d14e1bd7db5b73d5a7e23875d0c8428097c (patch)
treef842f82cac3b8f5b6181f45c5754c0dea8a1fc0a /src
parente7d184a90b8a9a68b0177e29d47f6d9b1abeadbf (diff)
downloadfluxbox_paul-c9270d14e1bd7db5b73d5a7e23875d0c8428097c.zip
fluxbox_paul-c9270d14e1bd7db5b73d5a7e23875d0c8428097c.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);