Skip to content

Instantly share code, notes, and snippets.

@creationix
Created December 3, 2014 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creationix/804045fd48aa6374a74a to your computer and use it in GitHub Desktop.
Save creationix/804045fd48aa6374a74a to your computer and use it in GitHub Desktop.
loading .so files from the bundle
-- Added to app/modules/require.lua in luvit/luvit
function formatters.so(data, module)
local dir = assert(uv.fs_mkdtemp("lib-XXXXXX"))
local filename = string.match(module.path, "[^/]+$")
local path = pathJoin(dir, filename)
local name = "luaopen_" .. string.match(filename, "^[^.]+");
local fd = uv.fs_open(path, "w", tonumber("600", 8))
uv.fs_write(fd, data, 0)
uv.fs_close(fd)
local fn = assert(package.loadlib(path, name))
module.exports = fn()
uv.fs_unlink(path)
uv.fs_rmdir(dir)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment