-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.lua
More file actions
43 lines (37 loc) · 981 Bytes
/
run.lua
File metadata and controls
43 lines (37 loc) · 981 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env luajit
local function split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
table.insert(t, str)
end
return t
end
local args = { ... }
local paramFile = io.open(args[1], "r")
local cruncher = io.open(args[2], "r")
local outputFile = io.open(args[3], "a")
local code = cruncher:read("*a")
io.close(cruncher)
local run = (loadstring or load)(code)
::next::
local params = split(paramFile:read("*l"))
if params then
local ok, runOutput = pcall(run, (table.unpack or unpack)(params))
if not ok then
print(runOutput)
else
local outputLine = ""
for i, v in ipairs(runOutput) do
outputLine = outputLine .. tostring(v) .. " "
end
outputLine = outputLine .. "\n"
outputFile:write(outputLine)
outputFile:flush()
end
goto next
end
paramFile:close()
outputFile:close()