Skip to content

Commit

Permalink
fix: populate ... for required modules
Browse files Browse the repository at this point in the history
Fixes #689.
  • Loading branch information
hishamhm committed Sep 4, 2023
1 parent 8b950e3 commit 9667697
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions spec/cli/run_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ describe("tl run", function()
]], output)
end)

it("passes standard arguments to required chunks", function()
local dir_name = util.write_tmp_dir(finally, {
["ld.tl"] = [[
require("foo")
print("Done")
]],
["foo.tl"] = [[
print(...)
]]
})
local pd, output
util.do_in(dir_name, function()
pd = io.popen(util.tl_cmd("run", "ld.tl"), "r")
output = pd:read("*a")
end)
util.assert_popen_close(0, pd:close())
util.assert_line_by_line([[
foo ./foo.tl
Done
]], output)
end)

describe("-l --require", function()
it("can require a module from the CLI like Lua", function()
local dir_name = util.write_tmp_dir(finally, {
Expand Down
2 changes: 1 addition & 1 deletion tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10825,7 +10825,7 @@ local function tl_package_loader(module_name)
local chunk, err = load(code, "@" .. found_filename, "t")
if chunk then
return function()
local ret = chunk()
local ret = chunk(module_name, found_filename)
package.loaded[module_name] = ret
return ret
end
Expand Down
2 changes: 1 addition & 1 deletion tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -10825,7 +10825,7 @@ local function tl_package_loader(module_name: string): any
local chunk, err = load(code, "@" .. found_filename, "t")
if chunk then
return function(): any
local ret = chunk()
local ret = chunk(module_name, found_filename)
package.loaded[module_name] = ret
return ret
end
Expand Down

0 comments on commit 9667697

Please sign in to comment.