Skip to content

Commit d6e102a

Browse files
authored
Let Lua sort the package.loaded table (#922)
* Add failing test for tl with a simple Lua module * Don't clear the loaded table
1 parent ec648bc commit d6e102a

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

spec/lang/loader/loader_spec.lua

+31
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,36 @@ describe("tl.loader", function()
3030
@.]] .. util.os_sep .. [[file1.tl
3131
]], output)
3232
end)
33+
it("works properly with the package.loaded table", function()
34+
local dir_name = util.write_tmp_dir(finally, {
35+
["module.lua"] = [[
36+
package.loaded['module'] = { worked = 'it works' }
37+
38+
return nil
39+
]],
40+
["module.d.tl"] = [[
41+
local record module
42+
worked: string
43+
end
44+
45+
return module
46+
]],
47+
["main.tl"] = [[
48+
local m = require 'module'
49+
print(type(m))
50+
print(m.worked)
51+
]]
52+
})
53+
local pd, output
54+
util.do_in(dir_name, function()
55+
pd = io.popen(util.tl_cmd("run", "main.tl"), "r")
56+
output = pd:read("*a")
57+
end)
58+
util.assert_popen_close(0, pd:close())
59+
util.assert_line_by_line([[
60+
table
61+
it works
62+
]], output)
63+
end)
3364
end)
3465
end)

tl.lua

-1
Original file line numberDiff line numberDiff line change
@@ -14165,7 +14165,6 @@ local function tl_package_loader(module_name)
1416514165
loader_data = found_filename
1416614166
end
1416714167
local ret = chunk(modname, loader_data)
14168-
package.loaded[module_name] = ret
1416914168
return ret
1417014169
end, found_filename
1417114170
else

tl.tl

-1
Original file line numberDiff line numberDiff line change
@@ -14165,7 +14165,6 @@ local function tl_package_loader(module_name: string): any, any
1416514165
loader_data = found_filename
1416614166
end
1416714167
local ret = chunk(modname, loader_data)
14168-
package.loaded[module_name] = ret
1416914168
return ret
1417014169
end, found_filename
1417114170
else

0 commit comments

Comments
 (0)