-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04d816a
commit 2ac7a01
Showing
6 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
file_patcher = { | ||
preprocessors = {} | ||
} | ||
|
||
require("file_patcher.mod") | ||
|
||
return file_patcher |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function file_patcher.add_preprocessor(fn) | ||
table.insert(file_patcher.preprocessors, fn) | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function file_patcher.load_and_patch(name, pre_content_write, post_content_write) | ||
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 | ||
|
||
file_patcher.write_to_file(created_file, pre_content_write) | ||
file_patcher.rewrite_file_content(created_file, modulepath) | ||
file_patcher.write_to_file(created_file, post_content_write) | ||
|
||
created_file:close() | ||
local to_compile = io.open("module.lua", "rb") | ||
return assert(load(assert(to_compile:read("*a")), modulepath)) | ||
end | ||
return require(name) | ||
end | ||
|
||
file_patcher.add_preprocessor(file_patcher.load_and_patch) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require("file_patcher.add_preprocessor") | ||
require("file_patcher.load_and_patch") | ||
require("file_patcher.rewrite_content") | ||
require("file_patcher.write_to_file") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function file_patcher.rewrite_file_content(created_file, modulepath) | ||
for line in io.lines(modulepath .. ".lua") do | ||
created_file:write("\n\t" .. line) | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function file_patcher.write_to_file(created_file, content) | ||
created_file:write(content) | ||
end |