darklua icon indicating copy to clipboard operation
darklua copied to clipboard

A rule for injecting libraries

Open jiwonz opened this issue 1 year ago • 3 comments

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))

jiwonz avatar Sep 11 '24 05:09 jiwonz

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.

nightcycle avatar Sep 11 '24 21:09 nightcycle

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.)

ewd3v avatar Jan 24 '25 18:01 ewd3v

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"?)

ewd3v avatar Jan 24 '25 19:01 ewd3v