最近寫了一個newlisp_armory庫,用來實現一些newlisp自身不支持的操做。好比跨windows和ubuntu的目錄拷貝功能等。git
本身用的時候,發現沒有API reference文檔參考,很不方便。因而學習瞭如何用註釋生成文檔。github
在Ubuntu環境下,首先要下載newlispdoc程序的源碼:http://newlisp.org/syntax.cgi?code/newlispdoc.txtubuntu
將文件重命名爲newlispdoc,添加執行權限,複製到/usr/bin目錄下。windows
也可直接從個人github項目中得到:https://github.com/csfreebird/newlisp_armory.gitapp
而後注意註釋的寫法,下面是個例子:less
;; file.lsp ;; @module file ;; @description file module provides some file operations on both Ubuntu and Windows ;; @location file.lsp ;; @version 1.0 ;; @author Dean Chen ;; @example ;; (let ((test-dir1 (append (real-path) file:file-seperator "a")) (test-dir2 (append (real-path) file:file-seperator "b"))) ;; (make-dir test-dir1) ;; (make-dir test-dir2) ;; (if (directory? test-dir1) ;; (begin ;; (unless (catch (file:copy-folder test-dir1 test-dir2) 'result) ;; (println (append "catch error: " result)) ;; (println "test copy-folder failed")) ;; (file:remove-folder test-dir1) ;; (file:remove-folder test-dir2)))) (context 'file) ;; @syntax (file:init) ;; @throw Throw error if environment variable NEWLISP_ARMORY_HOME does not exist or is invalid ;; @throw Throw error if OS is not Windows or UBuntu ;; @note init function will be called automatically when loading file.lsp module, don't call it manually (define (init) (unless (env "NEWLISP_ARMORY_HOME") (throw-error "NEWLISP_ARMORY_HOME does not exist")) (unless (file? (env "NEWLISP_ARMORY_HOME")) (throw-error "NEWLISP_ARMORY_HOME points to a non-existing file")) (unless (directory? (env "NEWLISP_ARMORY_HOME")) (throw-error "NEWLISP_ARMORY_HOME points to a file instead of directory")) (set 'file-folder (append (env "NEWLISP_ARMORY_HOME") "/codes/file")) (if (= ostype "Linux") (load (append file-folder "/file_ubuntu.lsp")) (= ostype "Win32") (load (append file-folder "/file_win.lsp")) (throw-error (append "file tool doesn't support this OS for now, ostype:" ostype)) ))
如今運行命令產生doc:ide
newlispdoc file.lsp
因爲我還有幾個支持不一樣平臺的文件,file_ubuntu.lsp和file.win.lsp,彷佛newlispdoc沒有這麼智能。所以我將file_ubuntu.lsp的註釋複製到file.lsp中,不復制源代碼。學習
也可以生成。this
下面的截圖展現了個人doc:code
點擊連接後,進入詳細頁面: