如何获取 GNU Smalltalk 中当前的模块/脚本/文件名?
GNU Smalltalk 省略了 argv 中的脚本名称。
#!/usr/bin/env gst -f
| argv program |
argv := Smalltalk arguments.
(argv size) > 0 ifTrue: [
program := argv at: 1.
Transcript show: 'Program: ', program; cr.
] ifFalse: [
Transcript show: 'argv = {}'; cr.
]
$ ./scriptname.st
argv = {}
我看到有两种获取脚本名称的方法:
- 追踪一些 Smalltalk 方法,该方法返回类似于 Perl 变量
$0
的脚本名称。 - 跟踪多行 shebang 的语法并强制 GST 提供脚本名作为 argv 的第一个成员。下面是 Common Lisp 中的示例。
GNU Smalltalk omits the script name in argv.
#!/usr/bin/env gst -f
| argv program |
argv := Smalltalk arguments.
(argv size) > 0 ifTrue: [
program := argv at: 1.
Transcript show: 'Program: ', program; cr.
] ifFalse: [
Transcript show: 'argv = {}'; cr.
]
$ ./scriptname.st
argv = {}
I see two ways to get the script name:
- Track down some Smalltalk method which returns the script name akin to Perl's variable
$0
. - Track down syntax for a multiline shebang and force GST to supply the scriptname as the first member of argv. Here's an example in Common Lisp.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来最好的办法是使用 shebangs 将脚本名称强制为 ARGV,然后检查
Smalltalk getArgv: 1
是否以硬编码字符串结尾。发布于此处和 Rosetta 代码。
It seems the best that can be done is use shebangs to force the script name to ARGV, then check whether
Smalltalk getArgv: 1
ends with a hardcoded string.Posted here and on Rosetta Code.
你可以询问当前方法来自哪里:
thisContext method methodSourceFile printNl
。You can ask the current method where it comes from:
thisContext method methodSourceFile printNl
.