Software /
code /
prosody
Comparison
plugins/mod_console.lua @ 3557:58ab7e61d220
mod_console: Keep global variable assignments sandboxed by default.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Thu, 04 Nov 2010 18:44:57 +0500 |
parent | 3540:bc139431830b |
child | 3614:8b436cc88c0e |
comparison
equal
deleted
inserted
replaced
3556:d00fc909296e | 3557:58ab7e61d220 |
---|---|
25 local default_env_mt = { __index = def_env }; | 25 local default_env_mt = { __index = def_env }; |
26 | 26 |
27 prosody.console = { commands = commands, env = def_env }; | 27 prosody.console = { commands = commands, env = def_env }; |
28 | 28 |
29 local function redirect_output(_G, session) | 29 local function redirect_output(_G, session) |
30 local env = setmetatable({ print = session.print }, { __index = function (t, k) return rawget(_G, k); end, __newindex = function (t, k, v) rawset(_G, k, v); end }); | 30 local env = setmetatable({ print = session.print }, { __index = function (t, k) return rawget(_G, k); end }); |
31 env.dofile = function(name) | 31 env.dofile = function(name) |
32 local f, err = loadfile(name); | 32 local f, err = loadfile(name); |
33 if not f then return f, err; end | 33 if not f then return f, err; end |
34 return setfenv(f, env)(); | 34 return setfenv(f, env)(); |
35 end; | 35 end; |