这样的事情存在吗?
红宝石:
if __FILE__ == $0
main
end
珀尔:
unless(caller) {
main;
}
卢阿:
if type(package.loaded[(...)]) ~= "userdata" then
main(arg)
else
module(..., package.seeall)
end
这样的事情存在吗?
红宝石:
if __FILE__ == $0
main
end
珀尔:
unless(caller) {
main;
}
卢阿:
if type(package.loaded[(...)]) ~= "userdata" then
main(arg)
else
module(..., package.seeall)
end
异国情调的多线 shebangs 和 argv 诡计完成了这项工作。
请参阅罗塞塔守则。
脚本main.st:
"exec" "gst" "-f" "$0" "$0" "$@"
"exit"
Object subclass: ScriptedMain [
ScriptedMain class >> meaningOfLife [ ^42 ]
]
| main |
main := [
Transcript show: 'Main: The meaning of life is ', ((ScriptedMain meaningOfLife) printString); cr.
].
(((Smalltalk getArgc) > 0) and: [ ((Smalltalk getArgv: 1) endsWith: 'scriptedmain.st') ]) ifTrue: [
main value.
].