Browse Source

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

Graham Northup 4 years ago
parent
commit
817958a26b
Signed by: Grissess <grissess@nexusg.org> GPG Key ID: 5D000E6F539376FB
3 changed files with 53 additions and 4 deletions
  1. 1
    1
      .gitlab-ci.yml
  2. 3
    0
      README.md
  3. 49
    3
      programs/server.sol

+ 1
- 1
.gitlab-ci.yml View File

@@ -21,7 +21,7 @@ test_boot:
21 21
     stage: test
22 22
     script:
23 23
         - make
24
-        - ./sol r programs/test.sol | tee test_out.txt
24
+        - ./sol r programs/test.sol
25 25
 
26 26
 all_tests:
27 27
     stage: test

+ 3
- 0
README.md View File

@@ -1,6 +1,9 @@
1 1
 sol
2 2
 ===
3 3
 
4
+- **Stable Repo**: https://github.com/sol-lang/sol
5
+- **Dev Repo**: https://gitlab.cosi.clarkson.edu/grissess/sol-lang
6
+
4 7
 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:
5 8
 
6 9
 * A rather lightweight, [mostly] re-entrant, multi-user runtime that is in the process of being optimized and made cross-platform.

+ 49
- 3
programs/server.sol View File

@@ -1,7 +1,53 @@
1
-io.stdin:read(1)
1
+http = {
2
+	ERRORS = {
3
+		[400] = "Bad Request",
4
+		[500] = "Server Error",
5
+	}
6
+}
2 7
 
3
-print('HTTP/1.1 200 OK
8
+NL = '
9
+'
10
+CR = chr(13)
11
+
12
+func get_request()
13
+	result = {}
14
+
15
+	httpline = io.stdin:read(io.LINE)
16
+	httpline = httpline:split(NL)[0]
17
+	httpline = httpline:split(CR)[0]
18
+	parts = httpline:split(" ")
19
+
20
+	if (3 != (#parts)) || (parts[2] != "HTTP/1.1") then
21
+		error(400)
22
+	end
23
+
24
+	result.method = parts[0]
25
+	result.path = parts[1]
26
+	result.protocol = parts[2]
27
+
28
+	return result
29
+end
30
+
31
+out = try(get_request)
32
+success = out[0]
33
+value = out[1]
34
+
35
+if success then
36
+	print('HTTP/1.1 200 OK
37
+Content-type: text/plain
38
+
39
+Hello from Sol! You sent in these values:', value)
40
+else
41
+	if type(value) == "int" then
42
+		print('HTTP/1.1 ' + tostring(value) + ' ' + (http.ERRORS[value]) + '
43
+Content-type: text/plain
44
+
45
+Error ' + tostring(value) + ': ' + (http.ERRORS[value]))
46
+	else
47
+		print('HTTP/1.1 500 Server Error
4 48
 Content-type: text/plain
5 49
 
6
-Hello from Sol!')
50
+Internal error: ' + tostring(value))
51
+	end
52
+end
7 53
 

Loading…
Cancel
Save