[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

obsolete[LuaStudio] Evaluate LUA file from URL

Third version

--EvalURL.lua
load(Lib.Sys.Net.Http.requestUrl("http://u8.smalltalking.net/u8/profile/aleReimondo/516/Main.lua"))()


Second version

self cancelFileIn!
--EvaluateURL.lua
-- note that the contents at url must be a lua expression including return
doHttp = function (url)
	local fn,err=load(Lib.Sys.Net.Http.requestUrl(url))
	if fn then return fn() else error(err) end
end

doHttp("http://u8.smalltalking.net/u8/profile/aleReimondo/516/Main.lua")


Initial code

self cancelFileIn!
-- ReadLuaFromURL.lua
doHttp = function(url) 
	local http = Lib.Sys.Net.Http.new( url )

	http.onData = function(data)
	--	print(data)
		local path = string.gsub(url, "http://u8.smalltalking.net/u8/profile", "")
		local platform = Lib.Media.System.systemName()
		if platform == "ios" or patform == "android"
			then root = Lib.Media.FileSystem.File.documentsDirectory.nativePath .. "/"
			else root = "/"
		end
		path = root .. "m8n" .. path
		Lib.Sys.IO.File.saveContent(path, data)
		dofile(path)
	end

	http.onError = function(msg)
	   print(msg)
	end

	http.request(false)
end

doHttp("http://u8.smalltalking.net/u8/profile/aleReimondo/516/Main.lua")

Notes
Objections promoting changes to the initial code
  1. in original code all variables was defined as GLOBAL
  2. code copy the script to local file, then evaluate the file (can we ommit storing the contents?)
  3. can we make it shorter? (one line expression)