Skip to content

dlatchx/lualink

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

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 !

About

A linker for lua code

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages