A linker for lua code
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
rockspecs
.editorconfig
LICENSE
README.md
lualink.lua

README.md

lualink

A linker for lua code

lualink puts all your dependencies inside one file, so that you can embed it easily.

How does it work ?

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 foo.lua

-- main.lua

local foo = require "foo"

print "hello from main.lua"
foo.sayhello()
-- foo.lua

return {
	sayhello= function() print("hello from dep.lua") end
}

Just link it :

$ ./lualink -mmain=main.lua -mfoo=foo.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 "foo"

	print "hello from main.lua"
	foo.sayhello()
end

package.preload['foo'] = function()
	return {
		sayhello= function() print("hello from foo.lua") end
	}
end

require('main')

So it's not perfect:

  • You can't embed bytecode (but you can easily compile the file produced)
  • It alterates debug informations

Pull requests are open !