Hello,
I made a simple program for download some function strings from web and launch it.
It launches a simple web browser I made.
-- web program loader & launcher --
programurl = "http://pastebin.com/raw.php?i=Te159hKt"
-- Use this function to perform your initial setup
function setup()
count,global,allloaded,started,urllist,programname,message = 0,nil,nil,nil,{},nil,nil
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
if(global and _G[global] and allloaded) then
_G[global]:draw()
fill(170, 182, 150, 170); stroke(224, 226, 224, 68); strokeWidth(1); rectMode(CORNER)
rect(0,0,50,24); fill(0, 0, 0, 135); textMode(CORNER); text("back",0,0);
return
end
strokeWidth(5); fill(171, 183, 150, 255) stroke(225, 226, 225, 255); rectMode(CORNER);
rect(WIDTH/2-100,HEIGHT/2-100,200,200); fill(0, 0, 0, 255); textMode(CENTER)
textWrapWidth(200)
if started then text("loading...",WIDTH/2,HEIGHT/2)
elseif message then text(message,WIDTH/2,HEIGHT/2)
elseif programname then text(programname,WIDTH/2,HEIGHT/2)
else text("tap to download",WIDTH/2,HEIGHT/2) end
end
function touched(touch)
if(global and _G[global] and allloaded) then
if(touch.state == BEGAN) and touch.x < 50 and touch.y <24 then
allloaded = nil; started = nil;
else
_G[global]:touched(touch)
end
end
if not started then
if touch.x >= WIDTH/2-100 and touch.x <= WIDTH/2+100 then
if touch.y >= HEIGHT/2-100 and touch.y <= HEIGHT/2+100 then
if touch.state == BEGAN then start(); started = true; end end end end
end
function keyboard(key)
if(global and _G[global] and allloaded) then _G[global]:keyboard(key) end end
function start()
if global then count = 0; for i,v in pairs(urllist) do http.get(v,success,failed) end
else http.get(programurl,success,failed) end end
function success(data,status,headers)
if(status == 200) then
if global then
count = count + 1
tablename = string.match(data,"--%s*([^-]+)%s*--")
print(tablename.." downloaded")
local j,data2 = 0,""
for i=1,data:len() do char = data:sub(i,i);
if char:byte() ~= 13 and char:byte() ~= 194 and char:byte() ~= 160 then
j = j + 1; data2 = data2..char; end
end
_G[tablename] = loadstring(data2)()
print("Table "..tablename..","..data2:len().."byte was loaded")
if #urllist == count then message = nil
print("all finished"); _G[global]:init(); allloaded = true; end;
else
crlf = string.char(13)..string.char(10)
urllist = split(data:sub(data:find(crlf)+2),crlf)
programname,global = data:match("([^,]+),([^,"..crlf.."]+)"..crlf)
print("Program Name:"..programname..", Main table = "..global)
print("table urls:")
for i,v in ipairs(urllist) do print(v) end
started = nil
message = nil
end
else print(status..' : '..data) end
end
function failed(error) message = error; started = nil end
function split(str, delim)
-- Eliminate bad cases...
if string.find(str, delim) == nil then return { str } end
local result,pat,lastpos = {},"(.-)" .. delim .. "()",nil
for part, pos in string.gfind(str, pat) do table.insert(result, part); lastPos = pos; end
table.insert(result, string.sub(str, lastPos))
return result
end