Info:
A simple tool that takes all of the lua files from a folder, and compacts it into a single lua file/string. This allows for a full require
system from inside a single lua file/string.
Main use cases:
Since some Lua environments are heavily sandboxed, system commands, file reading/writing, and etc are blocked at runtime. So this loopholes that by compacting an entire file structure into a single string, which can simply be pasted and ran in the environment. It has 0 dependencies, and bootloads itself.
General Flow:
- write code in
your_folder
- set the load order in
your_folder/load_order.lua
(see example/test/load_order) - set
folder_path
toyour_folder
insidevfs.lua
(see vfs) - run
vfs_run.bat
orvfs.lua
in command prompt - do whatever with the generated output
Example usage:
Let's say we had this file layout. After it's packed into a single lua file, it'll look somethiing like this:
-- generated by vfs.lua
-- output written into output/vfs_output.lua and the clipboard
-- folder_path = example\test
local chunks = {
["init"] = "\
print(\"init\")\
",
["load_order"] = "\
return {\"init\", \"folder.init_2\"}\
\
-- this also works\
--[[\
return {\
[5] = \"init\",\
[10000] = \"folder.init_2\"\
}\
]]\
",
["folder.hello_world"] = "\
print(\"Hello world\")\
",
["folder.init_2"] = "\
print(\"init_2\")\
\
require(\"folder.hello_world\")\
",
}
--- directory format is same as lua's. ex: folder.folder_2.file
function require(directory)
-- implemenation not shown
-- basically pulls and loads the source code from chunks[directory]
end
local load_order = require("load_order")
local priorities = {}
for priority in pairs(load_order) do -- add all priorities
table.insert(priorities, priority)
end
table.sort(priorities) -- sort in ascending order
for _, priority in ipairs(priorities) do -- run in order from lowest to highest
local directory = load_order[priority]
require(directory)
end
This is the input folder: example/test
This is the full output: output/vfs_output
Requirements:
- Lua 5.1 or Lua 5.2 (luaforwindows is fast and simple to install on Windows)
- Windows only for now