-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcustom_require.lua
More file actions
26 lines (24 loc) · 929 Bytes
/
custom_require.lua
File metadata and controls
26 lines (24 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function actions_loader.custom_require(name)
if string.match( name, "actions") then
package.preload[name] = function(modulename)
local created_file = io.open("module.lua", "w+")
local modulepath = string.gsub(modulename, "%.", "/")
local path = "/"
local filename = string.gsub(path, "%?", modulepath)
local file = io.open(filename, "rb")
if file then
local header = actions_loader.extract_header(modulepath)
for _, fn in ipairs(actions_loader.preprocessors) do
fn(created_file, header, modulepath)
end
created_file:close()
-- Compile and return the module
local to_compile = io.open("module.lua", "rb")
return assert(load(assert(to_compile:read("*a")), modulepath))
end
end
return require(name)
else
return default_package_searchers2(name)
end
end