Advertisement
joebodo

apps.webrun.lua

Nov 30th, 2016
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. local function dourl(env, url)
  2.   local h = http.get(url)
  3.   if h then
  4.     local fn, m = load(h.readAll(), url, nil, getfenv(1))
  5.     h.close()
  6.     if fn then
  7.       return fn()
  8.     end
  9.   end
  10.   error('Failed to download ' .. url)
  11. end
  12.  
  13. local args = { ... }
  14. local BASE = 'https://raw.githubusercontent.com/kepler155c/opus/develop/'
  15.  
  16. local s, m = pcall(function()
  17.  
  18.   LUA_UPATH = BASE .. 'sys/apis'
  19.  
  20.   local env = { }
  21.   for k,v in pairs(getfenv(1)) do
  22.     env[k] = v
  23.   end
  24.   setmetatable(env, { __index = _G })
  25.  
  26.   _G.Util = dourl(env, BASE .. 'sys/apis/util.lua')
  27.   _G.requireInjector = dourl(env, BASE .. 'sys/apis/injector.lua')
  28.  
  29.   -- install vfs
  30.   local s, m = Util.runUrl(env, BASE .. 'sys/extensions/vfs.lua')
  31.   if not s then
  32.     error(m)
  33.   end
  34.  
  35.   -- install filesystem
  36.   fs.mount('',       'gitfs', args[2], args[3], args[4])
  37.  
  38.   -- start program
  39.   local s, m = os.run(getfenv(1), args[1] or 'startup')
  40.   if not s and m then
  41.     error(m)
  42.   end
  43. end)
  44.  
  45. if not s and m then
  46.   printError(m)
  47. end
  48.  
  49. if fs.restore then
  50.   fs.restore()
  51. end
  52.  
  53. _G.Util = nil
  54. _G.requireInjector = nil
  55.  
  56. print('press enter to continue')
  57. read()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement