さくらんぼのlambda日記

lambdaちっくなことからゲーム開発までいろいろ書きます。

Memo

hunchentootの簡単なサンプル。
あとで解説が付く予定。

(asdf:oos 'asdf:load-op 'hunchentoot)
(asdf:oos 'asdf:load-op 'cl-who)
(require :hunchentoot)
(require :cl-who)
(setq *server* (hunchentoot:start (make-instance 'hunchentoot:acceptor :port 3000)))

(hunchentoot:define-easy-handler (say-yo :uri "/yo") (name)
  (setf (hunchentoot:content-type*) "text/plain")
  (format nil "Hey!~@[ ~A~]!" name))

(hunchentoot:define-easy-handler (hoi-yo :uri "/ho") (name)
  (setf (hunchentoot:content-type*) "text/plain")
  (format nil "Hoi~@[ ~A~]!" name))


(hunchentoot:define-easy-handler (memo :uri "/memo/memo") (name)
  (setf (hunchentoot:content-type*) "text/plain")
  (format nil "this is memo site~@[ ~A~]!" name))

(hunchentoot:define-easy-handler (hoge :uri "/hoge") (name)
  (format nil "~A" (hello-world))
  )

;; ハンドラ定義
(defun hello-world ()
  (cl-who:with-html-output-to-string
      (str nil :prologue t)
    (:html (:head (:title "hoge"))
	   (:body (:h1 "varのぺーじ")))))
(setq hunchentoot:*default-content-type* "text/html; charset=utf-8")

(setq hunchentoot:*hunchentoot-default-external-format*
      (flex:make-external-format :utf-8 :eol-style :lf))