Skip to content

Commit 01b53e1

Browse files
committed
prefer loadstring when available
1 parent 8acc92c commit 01b53e1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/cli.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,23 @@ local function lines_from(file)
4646
end
4747

4848
local function load_chunk(content, chunkName, environment)
49-
if _VERSION == "Lua 5.1" then
49+
if type(loadstring) == "function" then
5050
local func, err = loadstring(content, chunkName)
5151
if not func then
5252
return nil, err
5353
end
54-
if environment then
54+
if environment and type(setfenv) == "function" then
5555
setfenv(func, environment)
56+
elseif environment and type(load) == "function" then
57+
return load(content, chunkName, "t", environment)
5658
end
5759
return func
5860
end
5961

62+
if type(load) ~= "function" then
63+
return nil, "No load function available"
64+
end
65+
6066
return load(content, chunkName, "t", environment)
6167
end
6268

0 commit comments

Comments
 (0)