-
Notifications
You must be signed in to change notification settings - Fork 0
/
doll.v02.0010.b.00.lisp
138 lines (103 loc) · 3.91 KB
/
doll.v02.0010.b.00.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#|----------------------------|#
#|--doll----an-offering-from--|#
#|--------------librecell-----|#
#|----------------------------|#
(ql:quickload '(:cl-ppcre :telnetlib))
#| quicklisp dependencies --^ |#
#| v-- package definition |#
(defpackage doll
"open maintain and handle a persistent socket stream"
(:use :cl :sb-thread :cl-ppcre :telnetlib)
(:export defbind
defthread
version *version* doll-version *doll-version* doll/version
hostname *hostname*
port *port*
connection *connection*
connect-to-host
listener-loop
format-to-connection
+build-development-version-of-doll+
listener-loop-hacky
doll doll1 doll2))
(in-package :doll)
#|----------------------------|#
#| generics/methods by macros |#
#|----------------------------|#
(defmacro defbind (name value)
"global parameter and generic method to retreive it by funcall"
`(progn
(defparameter ,(intern (concatenate 'string "*" (string name) "*")) ,value)
(defgeneric ,name ())
(defmethod ,name ()
(symbol-value ',(intern (concatenate 'string "*" (string name) "*"))))))
(defmacro defthread (&optional (name nil) &body body)
"when a name is provided, it and body is memoized in an association table"
(let ((thread-name (if name
(concatenate 'string "defined-thread-" (string name) "-")
"defined-thread-"))
(timestamp (get-internal-real-time)))
`(progn
(defun ,(intern (concatenate 'string "init-" (string name))) ()
(setf ,(intern (concatenate 'string "*thread-" thread-name (format nil "~D" timestamp) "*"))
(make-thread (lambda () ,@body) :name ,(concatenate 'string thread-name (format nil "~D" timestamp))))))))
(defbind version (sb-posix:time))
(defbind doll-version (cons 2.001 #\B))
(defun doll/version ()
"all versions and timestamps as values"
(values (cons (version) (doll-version))
(version)
*version*
(doll-version)
(sb-posix:time)
(get-universal-time)))
#| hostname or ASN |#
(defbind hostname "lambda.moo.mud.org")
#| port for connection |#
(defbind port 8888)
;; (defbind connection nil)
(defun connect-to-host ()
"* and #' for: - connection - ."
(defbind connection (open-telnet-session (hostname) (port))))
#|========================================================== |#
(defun format-to-connection (string)
" to (connection) / *connection* "
(defun +init-doll+ ()
(unwind-protect
(unless (fbound (connect-to-host))
(let*
((cons (doll/version) (cons (connection) . nil)))
((command (read-vailable-data (connection))))
(defun handle-stream-data ()
" peek stream for data doll handles "
())
#| super gross stuff soz |#
#| not just imperative, |#
#| nor just hacky... |#
(defun listener-loop-hacky ()
(handle-stream-data)
(read-available-data (connection))
(sleep 1)
(listener-loop-hacky))
(defun doll1 ()
"see why this is mildly hacky at best etc"
(make-thread #'listener-loop-hacky))
(defun doll2 ()
" doll repl but all this needs writing "
(let ((command (read-line)))
(format-tn *connection* "~%~a~%" command))
(doll2))
(defun doil ()
(doll1)
(doll2))
#| placeholder / notes code |#
(defthread listener-loop ()
(read-available-data (connection))
(listener-loop))
(progn
(when (stringp string)
(format-tn (connection) "~a~%" string)))))
(unwind-protect
(progn
(when (stringp string)
(format-tn (connection) "~a~%" string)))))