作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Lisp (SBCL 1.0.40.0.debian) 应用程序 (myfitnessdata),它使用以下代码来处理命令行参数:
(:use :common-lisp)
(:export #:main))
(in-package :myfitnessdata)
(require :sb-posix)
;; snip
(defun main ()
(if (= (length sb-ext:*posix-argv*) 3)
(let ((username (nth 0 sb-ext:*posix-argv*))
(password (nth 1 sb-ext:*posix-argv*))
(path (nth 2 sb-ext:*posix-argv*)))
(scrape (username password path)))
(show-usage)))
我正在使用以下 Lisp 代码编译此应用程序:
(load "myfitnessdata.lisp")
(save-lisp-and-die "myfitnessdata.bin" :executable t :toplevel 'myfitnessdata:main)
这会生成一个我可以运行的可执行文件。但是,sb-ext:*posix-argv*
列表始终为空。如果我运行以下命令:
./myfitnessdata.bin myusername mypassword /home/me/data
...那么我得到的只是(show-usage)
生成的使用说明。
我想我一定又错过了一些简单的东西 - 有人可以让我知道如何(save-lisp-and-die)
以便生成的可执行文件接受命令行参数吗?
最佳答案
解决方案,正如sbcl-help上的好人所建议的那样,就是使用像 buildapp 这样的工具编译应用程序。您可以指定一个入口点,该入口点被假定为具有一个参数的函数。在运行时,使用命令行参数列表调用该函数。
使用 buildapp,我的 main
功能现在是:
(defun main (args)
(if (= (length args) 4)
(let ((username (nth 1 args))
(password (nth 2 args))
(path (nth 3 args)))
(scrape username password path))
(show-usage)))
关于compilation - 如何将参数传递给保存的 SBCL 核心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5009853/
我是一名优秀的程序员,十分优秀!