Diff

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
line wrap: on
line diff
--- a/plugins/mod_admin_shell.lua	Thu Jul 29 20:16:11 2021 +0200
+++ b/plugins/mod_admin_shell.lua	Wed Aug 11 14:55:59 2021 +0200
@@ -135,8 +135,12 @@
 		return;
 	end
 
+	if useglobalenv and not session.globalenv then
+		session.globalenv = redirect_output(_G, session);
+	end
+
 	local chunkname = "=console";
-	local env = (useglobalenv and redirect_output(_G, session)) or session.env or nil
+	local env = (useglobalenv and session.globalenv) or session.env or nil
 	-- luacheck: ignore 311/err
 	local chunk, err = envload("return "..line, chunkname, env);
 	if not chunk then