aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2010-04-19 18:28:12 +0500
committerWaqas Hussain <waqas20@gmail.com>2010-04-19 18:28:12 +0500
commit5455626d0a09235b73f698a19d5a7ce9d41545be (patch)
treee8518d9fa4b8fa6a9eb07ddb3b55f7b81df2271e
parente0c9c76b44e32e17f17b06e546e5283728fdb706 (diff)
downloadprosody-5455626d0a09235b73f698a19d5a7ce9d41545be.tar.gz
prosody-5455626d0a09235b73f698a19d5a7ce9d41545be.zip
prosody: Set metatable on functions to allow easy access to upvalues.
-rwxr-xr-xprosody24
1 files changed, 24 insertions, 0 deletions
diff --git a/prosody b/prosody
index 46f3331f..c7f91456 100755
--- a/prosody
+++ b/prosody
@@ -123,6 +123,29 @@ function sandbox_require()
end
end
+function set_function_metatable()
+ local mt = {};
+ function mt.__index(f, upvalue)
+ local i, name, value = 0;
+ repeat
+ i = i + 1;
+ name, value = debug.getupvalue(f, i);
+ until name == upvalue or name == nil;
+ return value;
+ end
+ function mt.__newindex(f, upvalue, value)
+ local i, name = 0;
+ repeat
+ i = i + 1;
+ name = debug.getupvalue(f, i);
+ until name == upvalue or name == nil;
+ if name then
+ debug.setupvalue(f, i, value);
+ end
+ end
+ debug.setmetatable(function() end, mt);
+end
+
function init_global_state()
bare_sessions = {};
full_sessions = {};
@@ -418,6 +441,7 @@ read_config();
init_logging();
check_dependencies();
sandbox_require();
+set_function_metatable();
load_libraries();
init_global_state();
read_version();