Skip to content

Commit 5d5fc45

Browse files
authored
Add option to include lua files (#14)
* feat: add include option to build table allows to copy lua files into LUADIR while installing, for providing loader wrappers or type annotations. behaves like `modules` key: can be an array (file will be copied without renaming) or a `from => to` table
1 parent 6335143 commit 5d5fc45

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ build = {
4444
-- Optional: if set to `false` pass `--no-default-features` to cargo
4545
default_features = false,
4646

47+
-- Optional: copy additional files to lua dir, can specify source path
48+
include = {
49+
"file.lua",
50+
["path/to/another/file.lua"] = "another-file.lua",
51+
},
52+
4753
-- Optional: pass additional features
4854
features = {"extra", "features"}
4955
}

src/luarocks/build/rust-mlua.lua

+15
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ function mlua.run(rockspec, no_install)
8484
return nil, "Failed installing " .. src .. " in " .. dst .. ": " .. err
8585
end
8686
end
87+
88+
local cwd = dir.path(dir.dir_name(rockspec.local_abs_filename), rockspec.name)
89+
local luadir = path.lua_dir(rockspec.name, rockspec.version)
90+
91+
fs.make_dir(dir.dir_name(luadir))
92+
for from, to in pairs(rockspec.build.include) do
93+
if type(from) == "number" then
94+
from = to
95+
end
96+
to = dir.path(luadir, to)
97+
local ok, err = fs.copy(dir.path(cwd, from), to, "exec")
98+
if not ok then
99+
return nil, "Failed copying " .. from .. " in " .. to .. ": " .. err
100+
end
101+
end
87102
end
88103

89104
return true

0 commit comments

Comments
 (0)