Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Small changes to classes. Added Matcher class. Added igen program for…
… generating installers.
- Loading branch information
James King
committed
Sep 14, 2013
1 parent
5e40419
commit c32c0b3
Showing
7 changed files
with
129 additions
and
4 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
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
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
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
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,23 @@ | ||
| --@native string.find | ||
|
|
||
| --[[ | ||
| Used to match substrings of a string to a particular pattern. | ||
| ]] | ||
|
|
||
| --[[ | ||
| Constructs a matcher with the given pattern. | ||
| @param string:pattern Pattern to match. | ||
| ]] | ||
| function Matcher:init(pattern, str) | ||
| self.pattern = cast(pattern, "string") | ||
| self.string = cast(str, "string") | ||
| end | ||
|
|
||
| function Matcher:find() | ||
| self.left, self.right = self.string:find(pattern, (self.right or 0) + 1) | ||
| return self.left and true or false | ||
| end | ||
|
|
||
| function Matcher:matched() | ||
| return String.new(str:sub(self.left, self.right)) | ||
| 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,83 @@ | ||
| local _, err = pcall(function(...) | ||
| local USAGE = "Usage: igen <runnable> <name> <target>" | ||
|
|
||
| local args = { ... } | ||
| if #args < 3 then print(USAGE) end | ||
|
|
||
| local code = | ||
| [[ | ||
| local _, err = pcall(function(...) | ||
| local programName = '$' | ||
|
|
||
| if not fs.exists("/.see") then | ||
| print(programName .. " requires SEE to be installed. Downloading SEE installer...") | ||
| local installerCode = http.get("https://raw.github.com/Yevano/see/master/see/programs/installer").readAll() | ||
|
|
||
| while true do | ||
| print("Running installer.") | ||
| local inst = loadstring(installerCode) | ||
| setfenv(inst, setmetatable({ shell = shell }, { __index = _G })) | ||
| local _, err = pcall(inst) | ||
| if err then print(err) end | ||
|
|
||
| if fs.exists("/.see") then | ||
| break | ||
| end | ||
|
|
||
| write("SEE was not installed. Quit installation? (y/n) ") | ||
| while true do | ||
| local response = read() | ||
| if string.lower(response):gsub("%s", "") == "y" then | ||
| return | ||
| elseif string.lower(response):gsub("%s", "") == "n" then | ||
| break | ||
| else | ||
| print("Invalid input.") | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| local runnableBytes = '$' | ||
|
|
||
| write("Choose an install path for " .. programName .. ": ") | ||
| local installPath = "/" .. shell.resolve(read()) | ||
|
|
||
| local out = fs.open(installPath, "w") | ||
| out.write(runnableBytes) | ||
| out.close() | ||
|
|
||
| print(programName .. " was installed successfully.") | ||
| end, ...) | ||
|
|
||
| if err then | ||
| error(err) | ||
| end | ||
| ]] | ||
|
|
||
| local runnableRead = fs.open("/" .. shell.resolve(args[1]), "r") | ||
| local runnableBytes = runnableRead.readAll() | ||
| runnableRead.close() | ||
| local name = args[2] | ||
| local target = "/" .. shell.resolve(args[3]) | ||
|
|
||
| local runnableTable = { } | ||
| for i = 1, #runnableBytes do | ||
| runnableTable[i] = "\\" .. runnableBytes:sub(i, i):byte() | ||
| end | ||
|
|
||
| local runnableConverted = table.concat(runnableTable) | ||
|
|
||
| local f = code:find("$", 1, true) | ||
| code = code:sub(1, f - 1) .. name .. code:sub(f + 1) | ||
| f = code:find("$", f + #name, true) | ||
| code = code:sub(1, f - 1) .. runnableConverted .. code:sub(f + 1) | ||
|
|
||
| local targetWrite = fs.open(target, "w") | ||
| targetWrite.write(code) | ||
| targetWrite.close() | ||
| end, ...) | ||
|
|
||
| if err then | ||
| error(err) | ||
| 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