Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/lua/vm/stdlib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,10 @@ defmodule Lua.VM.Stdlib do

# Find a module file by searching the patterns
defp find_module_file(modname, patterns) do
resolved = String.replace(modname, ".", "/")

Enum.find_value(patterns, {:error, :not_found}, fn pattern ->
file_path = String.replace(pattern, "?", modname)
file_path = String.replace(pattern, "?", resolved)

case File.read(file_path) do
{:ok, content} -> {:ok, file_path, content}
Expand Down
18 changes: 18 additions & 0 deletions test/lua/vm/stdlib/package_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,22 @@ defmodule Lua.VM.Stdlib.PackageTest do
assert {[true, 1], _} = eval_with_path(code, tmp_dir)
end
end

describe "dotted module names" do
@tag :tmp_dir
test "require('foo.bar') resolves dots to directory separators", %{tmp_dir: tmp_dir} do
File.mkdir_p!(Path.join(tmp_dir, "foo"))

File.write!(Path.join([tmp_dir, "foo", "bar.lua"]), """
return { ok = true }
""")

code = ~S"""
local m = require("foo.bar")
return m.ok
"""

assert {[true], _} = eval_with_path(code, tmp_dir)
end
end
end
Loading