Browse Source

Sol Part 57: I Can't Believe It's Not Lua!

master
Graham Northup 5 years ago
parent
commit
817958a26b
Signed by: grissess GPG Key ID: 5D000E6F539376FB
  1. 2
      .gitlab-ci.yml
  2. 3
      README.md
  3. 52
      programs/server.sol

2
.gitlab-ci.yml

@ -21,7 +21,7 @@ test_boot:
stage: test
script:
- make
- ./sol r programs/test.sol | tee test_out.txt
- ./sol r programs/test.sol
all_tests:
stage: test

3
README.md

@ -1,6 +1,9 @@
sol
===
- **Stable Repo**: https://github.com/sol-lang/sol
- **Dev Repo**: https://gitlab.cosi.clarkson.edu/grissess/sol-lang
Sol a scripting language (whose name is subject to change) that aims to take the best of Lua and Python, and look a little bit like Javascript in the process :) . Sol's most outstanding features include:
* A rather lightweight, [mostly] re-entrant, multi-user runtime that is in the process of being optimized and made cross-platform.

52
programs/server.sol

@ -1,7 +1,53 @@
io.stdin:read(1)
http = {
ERRORS = {
[400] = "Bad Request",
[500] = "Server Error",
}
}
print('HTTP/1.1 200 OK
NL = '
'
CR = chr(13)
func get_request()
result = {}
httpline = io.stdin:read(io.LINE)
httpline = httpline:split(NL)[0]
httpline = httpline:split(CR)[0]
parts = httpline:split(" ")
if (3 != (#parts)) || (parts[2] != "HTTP/1.1") then
error(400)
end
result.method = parts[0]
result.path = parts[1]
result.protocol = parts[2]
return result
end
out = try(get_request)
success = out[0]
value = out[1]
if success then
print('HTTP/1.1 200 OK
Content-type: text/plain
Hello from Sol! You sent in these values:', value)
else
if type(value) == "int" then
print('HTTP/1.1 ' + tostring(value) + ' ' + (http.ERRORS[value]) + '
Content-type: text/plain
Error ' + tostring(value) + ': ' + (http.ERRORS[value]))
else
print('HTTP/1.1 500 Server Error
Content-type: text/plain
Hello from Sol!')
Internal error: ' + tostring(value))
end
end
Loading…
Cancel
Save