-
-
Save creationix/804045fd48aa6374a74a to your computer and use it in GitHub Desktop.
loading .so files from the bundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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