From 0e7f307d0384a32e82d769f8d5c649e533439766 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Mon, 9 Aug 2021 11:59:51 -0700 Subject: [PATCH] Allow passing environment table to import function --- ldoc.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ldoc.lua b/ldoc.lua index d259f07..6601ae1 100644 --- a/ldoc.lua +++ b/ldoc.lua @@ -257,8 +257,21 @@ local ldoc_contents = { } if args.UNSAFE_NO_SANDBOX then - function ldoc.import(t) - return _G[t] + local select_locals = { + ["args"] = args, + } + + function ldoc.import(t, env) + local retval = select_locals[t] + if not retval then + retval = _G[t] + end + + if env then + env[t] = retval + end + + return retval end table.insert(ldoc_contents, 'import')