I know everyone is excited about shaders, but there are a couple of other new features that are also pretty exciting! One such feature is the ability to read, list, and save tabs in a project. To celebrate, I’ve created a function that, given a URL that points to a file, will create a new tab in the current project with the contents of the downloaded file.
-- ImportURL
-- Usage: importURL([tabname,] url)
function importURL(tabname, url)
tabname, url = url and tabname, url or tabname
if not tabname then
tabname = url:sub(#url - url:reverse():find("/", 1) + 2, #url)
tabname = tabname:sub(1, tabname:find("%.", 1) - 1)
end
http.request(url, function(data, status, headers)
if status == 200 then
saveProjectTab(tabname, data)
print("Tab '"..tabname.."' created")
else
print("Failed to download '"..url.."' to '"..tabname.."'")
end
end)
end
I recommend making a project with this as the only file in it (other than main), so that you can include it as a dependency for other projects. Then just call importURL() in your project with the URL of the file you want to download and import as a tab. Here’s an example of downloading the awesome middleclass.lua from kikito’s public github repo:
importURL("https://raw.github.com/kikito/middleclass/master/middleclass.lua")
When complete, a new tab named “middleclass” will be created in your project with the contents of middleclass.lua. You can also specify the desired tab name as an optional first argument if you’d like:
importURL("MiddleClass", "https://raw.github.com/kikito/middleclass/master/middleclass.lua")
One thing to be aware of is that the new tab will not appear until after you exit your project and re-enter it.
.@Simeon: I’m not sure how easy this would be to do, but it might be worth considering to make Codea aware of when saveProjectTab() is called while a program is executing, and when execution ends and flow is returned to the editor, reload all of the tabs.