start on HTTP client

This commit is contained in:
Kartik K. Agaram 2021-11-21 14:33:50 -08:00
parent fdd87c5eda
commit f7ab5dd291
4 changed files with 9 additions and 36 deletions

View File

@ -59,7 +59,8 @@ comprehend and modify the programs they use. If it's not clear how to provide
that experience for some kinds of Lua programs, I'd rather disable support for
them in Teliva and let people use regular Lua. Or other platforms!
- This approach doesn't make sense for batch programs, I think.
- This approach doesn't make sense for batch programs, I think. I also don't
yet have a good story for building server programs in this way.
- I don't know how to obtain a simple, shallow graphics stack, so there's no
support for graphics at the moment.

7
chesstv.tlv Normal file
View File

@ -0,0 +1,7 @@
teliva_program = {
main = [==[
function main()
socket.http.get("http://example.com")
curses.getch()
end]==],
}

View File

@ -1,8 +0,0 @@
teliva_program = {
main = [==[
function main()
local x = json.decode("[10, 20, 30]")
curses.mvaddstr(5, 5, tostring(x[1]))
curses.getch()
end]==],
}

View File

@ -1,27 +0,0 @@
teliva_program = {
main = [==[
function main()
local server = assert(socket.bind("*", 8080))
server:settimeout(1)
curses.mvaddstr(1, 1, "Server bound and waiting for one request")
curses.refresh()
local available_sockets, _, error = socket.select({server}, nil)
for _, available_socket in ipairs(available_sockets) do
local client = available_socket:accept()
curses.mvaddstr(2, 1, "Connection received")
curses.refresh()
client:settimeout(1)
local line, error = client:receive()
if error then
curses.mvaddstr(3, 1, "error")
curses.refresh()
server:close()
else
curses.stdscr():mvaddstr(3, 1, "received:")
curses.stdscr():mvaddstr(4, 3, line)
curses.refresh()
end
end
curses.getch()
end]==],
}