如何将参数传递给保存的 SBCL 核心?
我有一个 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)
以便生成的可执行文件采用命令行参数吗?
I have a Lisp (SBCL 1.0.40.0.debian) application (myfitnessdata), which uses the following code to process command line arguments:
(: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)))
I am compiling this application using the following Lisp code:
(load "myfitnessdata.lisp")
(save-lisp-and-die "myfitnessdata.bin" :executable t :toplevel 'myfitnessdata:main)
This produces an executable that I can run. However, the sb-ext:*posix-argv*
list is always empty. If I run the following:
./myfitnessdata.bin myusername mypassword /home/me/data
... then all I get is the usage instructions produced by (show-usage)
.
I think I must be missing something simple again - could someone please let me know how to (save-lisp-and-die)
such that the resultant executable takes command line arguments?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 sbcl-help 上的好人所建议的解决方案是使用 buildapp 等工具来编译应用程序。您可以指定一个入口点,该入口点被假定为具有一个参数的函数。在运行时,使用命令行参数列表调用该函数。
使用 buildapp,我的
main
函数现在是:The solution, as suggested by the good folks on sbcl-help, is to use a tool like buildapp to compile the app. You can specify an entry point, which is assumed to be a function with one argument. At run-time, that function is called with a list of command-line parameters.
Using buildapp, my
main
function is now: