Skip to content
Permalink
Browse files
Added an installer. Added standard library argument to SEE executor p…
…rogram.
  • Loading branch information
James King committed Aug 9, 2013
1 parent d0b7f98 commit e724673
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 9 deletions.
@@ -115,9 +115,10 @@ SeeVM.__index = SeeVM
--[[
Creates a new SeeVM
]]
function SeeVM.new(natives)
function SeeVM.new(natives, seePath)
local self = { }
setmetatable(self, SeeVM)
self.seePath = seePath

self.standardGlobals = { }
for k, v in pairs(StandardGlobals) do
@@ -207,7 +208,8 @@ function SeeVM:loadClassFromAny(name)
if class then return class end

-- Load from the standard library.
class, err = self:loadClassFromFile(fs.combine("/see/lib/", name:gsub("%.", "/") .. ".lua"), name)
local p = name:gsub("%.", "/")
class, err = self:loadClassFromFile(fs.combine(fs.combine(self.seePath, "/lib/"), p) .. ".lua", name)

if class then return class end

@@ -309,8 +311,8 @@ function SeeVM:loadClass(def, annotations, name)
function class.new(...)
if not class.init then error("Could not instantiate class " .. name .. ". No init method.") end
local self = { }
self.__type = class
setmetatable(self, class.__meta)
self.__type = class
self:init(...)
return self
end
@@ -0,0 +1,106 @@
local REPO_URL = "https://raw.github.com/Yevano/see/master/see/"
local SUPPORTS_COLOR = term.isColor()

local MAKE_PATHS = {
"apis/",
"lib/",
"lib/see/",
"lib/see/base/",
"lib/see/concurrent/",
"lib/see/rt/",
"lib/see/util/",
"programs/"
}

local DL_PATHS = {
"apis/see",
"lib/see/base/Array.lua",
"lib/see/base/Exception.lua",
"lib/see/base/Object.lua",
"lib/see/base/String.lua",
"lib/see/base/System.lua",
"lib/see/concurrent/Thread.lua",
"lib/see/rt/Class.lua",
"lib/see/rt/InvalidArgumentException.lua",
"lib/see/rt/RuntimeException.lua",
"lib/see/util/ArgumentUtils.lua",
"lib/see/util/Math.lua",
"programs/see"
}

local function fail(err)
if SUPPORTS_COLOR then
term.setTextColor(colors.red)
end

print(err)

if SUPPORTS_COLOR then
term.setTextColor(colors.white)
end

while true do
write("Retry installation? (y/n): ")
local response = read()
if string.lower(response):gsub("%s", "") == "y" then
print("")
return true
elseif string.lower(response):gsub("%s", "") == "n" then
return false
end
print("Invalid input.")
end
end

while true do
while true do
local downloaded = 0

write("SEE Installer\nChoose an install path: ")
local installPath = shell.resolve(read())

local suc, err = pcall(fs.makeDir, installPath)
if not suc then
if fail("Could not create installation directory.") then break end
return
end

print("Setting up directory structure.")

for i = 1, #MAKE_PATHS do
fs.makeDir(fs.combine(installPath, MAKE_PATHS[i]))
end

print("Downloading SEE files from repository.")

local url, httpFail
for i = 1, #DL_PATHS do
url = REPO_URL .. DL_PATHS[i]
print("Downloading " .. DL_PATHS[i])
local readHandle = http.get(url)
if readHandle.getResponseCode() ~= 200 then
httpFail = true
break
end

local _, relativePathStart = url:find(REPO_URL, 1, true)
local writePath = fs.combine(installPath, url:sub(relativePathStart + 1))

local writeHandle = fs.open(writePath, "w")
writeHandle.write(readHandle.readAll())

readHandle.close()
writeHandle.close()
end

if httpFail then
if fail("File download failed for url " .. url .. ".") then
break
end
else
print("SEE was installed successfully.")
end

return
end
end
@@ -20,7 +20,7 @@ local _, err = pcall(function(...)
MainClass.main(args)
end

local USAGE = "Usage: see <-r <classPath> <mainClass>>|<-p <dir>>|<-u <archive>>|<-help>"
local USAGE = "Usage: see <-r <seePath> <classPath> <mainClass> <args>>|<-p <dir>>|<-u <archive>>|<-help>"
local args = {...}
local op = args[1]

@@ -30,12 +30,12 @@ local _, err = pcall(function(...)

if op == "-r" then
--Run option.
vm = see.SeeVM.new(natives)
classPath = shell.resolve(args[2])
vm = see.SeeVM.new(natives, shell.resolve(args[2]))
classPath = shell.resolve(args[3])
table.insert(vm.classPaths, classPath)
local mainClassName = args[3]
local mainClassName = args[4]
local programArgs = { }
for i = 4, #args do
for i = 5, #args do
table.insert(programArgs, args[i])
end

2 test
@@ -1 +1 @@
shell.run("/see/programs/see", "-r", "/see/test/", "see.example.Test", "Yevano")
shell.run("/see/programs/see", "-r", "/see/", "/see/test/", "see.example.Test", "Yevano")

0 comments on commit e724673

Please sign in to comment.