diff --git a/lib/lua/vm/stdlib.ex b/lib/lua/vm/stdlib.ex index 597f572..c9e99c5 100644 --- a/lib/lua/vm/stdlib.ex +++ b/lib/lua/vm/stdlib.ex @@ -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} diff --git a/test/lua/vm/stdlib/package_test.exs b/test/lua/vm/stdlib/package_test.exs index 3486477..f0c815a 100644 --- a/test/lua/vm/stdlib/package_test.exs +++ b/test/lua/vm/stdlib/package_test.exs @@ -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