A linker for lua code
lua-link puts all your dependencies inside one file, so that you can embed it easily.
It just puts the content of your file as functions inside package.preload.
Let's say your lua program has two files: main.lua and its dependency dep.lua
-- main.lua
local m = require "mymodule"
print "hello from main.lua"
m.sayhello()
-- dep.lua
return {
sayhello= function() print("hello from dep.lua") end
}
Just link it :
$ ./lua-link main=main.lua mymodule=dep.lua -o myapp.lua
Now all your dependencies are inside myapp.lua
$ rm main.lua dep.lua
$ lua myapp.lua
hello from main.lua
hello from dep.lua
As you can see, it just puts your files inline.
-- myapp.lua
package.preload['main'] = function()
local m = require "mymodule"
print "hello from main.lua"
m.sayhello()
end
package.preload['mymodule'] = function()
return {
sayhello= function() print("hello from dep.lua") end
}
end
require('main')
So it's not perfect:
- It only works if your code calls require. It wont't work with dofile
- You can't embed bytecode (but you can easily compile the file produced)
- It alterates debug informations
Pull requests are open !