A rule for injecting libraries
inject_modules rule would be great for injecting libraries and global functions too (exampe: injecting libraries of luau written in pure lua to emulate luau outside of luau)
Example
.darklua.json5
rules: {
inject_libraries: {
libraries: [
{
name: "buffer",
path: "buffer.lua"
},
{
name: "typeof",
path: "typeof.lua"
}
]
}
}
src/main.lua
print(typeof(buffer.create))
After processing:
local buffer = require("{top_path}/_DARKLUA_lib{buffer_blake3_hash}")
local typeof = require("{top_path}/_DARKLUA_lib{typeof_blake3_hash}")
print(typeof(buffer.create))
Completely agree! I had to do this just yesterday with a bash script in order to get the task library added to code that I deploy in both lune and roblox.
Bump this, would be amazing to have libraries that you can just access as globals without having to constantly import them! (Also great for compatbility libraries as op said.)
Perhaps this could have an option for code to run to import specific libraries?
An example would be importing "task" as require("@lune/task") to reduce the overhead of creating a file that returns the same thing.
So like:
{
name: "task",
code: 'require("@lune/task")'
}
(Unsure what to call the field, maybe "custom"?)