SHOW:
|
|
- or go back to the newest paste.
1 | ---- | |
2 | --Original compile and run source code developed by Pharap | |
3 | --http://www.computercraft.info/forums2/index.php?/user/3218-pharap/ | |
4 | -- | |
5 | --The original source can be found here: | |
6 | --Compile.lua: http://pastebin.com/S520NYMV | |
7 | --Run.lua: http://pastebin.com/xjBgXmfy | |
8 | --- | |
9 | ||
10 | --Argument Checking-- | |
11 | local args = {...} | |
12 | if(#args<2)then error("Need two arguments",0) end | |
13 | if(not fs.exists(args[1]))then error("Invalid filename",0) end | |
14 | ||
15 | --Functionality-- | |
16 | local function compile(inFile,outFile) | |
17 | local file = fs.open(inFile,"r") | |
18 | local dump = string.dump(loadstring(file.readAll())) | |
19 | file.close() | |
20 | file = fs.open(outFile,"wb") | |
21 | local clock = os.clock() + 4.5 | |
22 | for i = 1,#dump do | |
23 | file.write(string.byte(dump:sub(i,i))) | |
24 | if(os.clock()>=clock)then | |
25 | os.queueEvent"" -- Prevents 5 second loop. | |
26 | coroutine.yield() -- Suggested by pingoleon60 and theoriginalbit | |
27 | clock = os.clock() + 4.5 | |
28 | end | |
29 | end | |
30 | file.close() | |
31 | end | |
32 | ||
33 | compile(args[1],args[2]) |