Comparison

plugins/mod_admin_shell.lua @ 11736:ddb87df3de30

mod_admin_shell: Keep unrestricted environment for session lifetime Makes it so that global values set in the environment are kept longer than within one line, and thus can be used until the session ends. They still don't pollute the global environment, which is an error anyway. Thanks phryk for noticing.
author Kim Alvefur <zash@zash.se>
date Wed, 11 Aug 2021 14:55:59 +0200
parent 11607:03eb4c0dca27
child 11831:94cd363116a3
comparison
equal deleted inserted replaced
11735:7d29167bfcc3 11736:ddb87df3de30
133 commands[line:lower()](session, line); 133 commands[line:lower()](session, line);
134 event.origin.send(result); 134 event.origin.send(result);
135 return; 135 return;
136 end 136 end
137 137
138 if useglobalenv and not session.globalenv then
139 session.globalenv = redirect_output(_G, session);
140 end
141
138 local chunkname = "=console"; 142 local chunkname = "=console";
139 local env = (useglobalenv and redirect_output(_G, session)) or session.env or nil 143 local env = (useglobalenv and session.globalenv) or session.env or nil
140 -- luacheck: ignore 311/err 144 -- luacheck: ignore 311/err
141 local chunk, err = envload("return "..line, chunkname, env); 145 local chunk, err = envload("return "..line, chunkname, env);
142 if not chunk then 146 if not chunk then
143 chunk, err = envload(line, chunkname, env); 147 chunk, err = envload(line, chunkname, env);
144 if not chunk then 148 if not chunk then