1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-28 00:39:30 +00:00

Added some examples, fixed a typo

This commit is contained in:
Firew0lf 2015-12-31 15:41:09 +01:00
parent b87b2676e6
commit e10a101a4a
8 changed files with 225 additions and 2 deletions

View file

@ -0,0 +1,43 @@
local ctr = require("ctr")
local gfx = require("ctr.gfx")
local hid = require("ctr.hid")
local httpc = require("ctr.httpc")
local err = 0
local addr = "https://wtfismyip.com/text"
local dls = 0
local context = assert(httpc.context())
assert(context:open(addr))
assert(context:beginRequest())
local data = assert(context:downloadData())
while ctr.run() do
hid.read()
keys = hid.keys()
if keys.held.start then break end
if keys.down.b then
assert(context:open(addr))
assert(context:beginRequest())
data = assert(context:downloadData())
dls = dls + 1
end
gfx.startFrame(gfx.TOP)
gfx.text(0, 0, data)
gfx.text(0, 20, "Downloaded "..dls.." times.")
gfx.endFrame()
gfx.startFrame(gfx.BOTTOM)
gfx.text(2, 2, "HTTP Contexts example")
gfx.text(2, 20, "The data is downloaded from '"..addr.."'.")
gfx.text(2, 30, "Press [B] to redownload.")
gfx.endFrame()
gfx.render()
end
context:close()