Software /
code /
prosody
Comparison
plugins/mod_console.lua @ 3407:15f633285755
mod_console: Override dofile() in the console environment (this lets print() print to the console session for example).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 26 Jul 2010 01:52:04 +0500 |
parent | 3404:33c81ee280e3 |
child | 3452:2d1a5d8893c2 |
comparison
equal
deleted
inserted
replaced
3406:748246005893 | 3407:15f633285755 |
---|---|
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 return 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, __newindex = function (t, k, v) rawset(_G, k, v); end }); |
31 env.dofile = function(name) | |
32 local f, err = loadfile(name); | |
33 if not f then return f, err; end | |
34 return setfenv(f, env)(); | |
35 end; | |
36 return env; | |
31 end | 37 end |
32 | 38 |
33 console = {}; | 39 console = {}; |
34 | 40 |
35 function console:new_session(conn) | 41 function console:new_session(conn) |