编辑 - 添加有关stc 和stx 的信息
恐怕您不能直接在 Smalltalk/X(-jv 分支) 中使用 GNU Smalltalk 代码。此外,很高兴看到您在 Smalltalk 问题系列中的最终目标是什么。
了解 Smalltalk 设计为在 IDE 中工作很重要,如果您想构建应用程序,您应该使用提供的 IDE。如果你想构建一个示例应用程序,Smalltalk/X 甚至还有 guide。当然,这并不意味着您无法从命令行启动脚本(Smalltalk/X 在 shell 中非常强大)。
话虽如此,Sublime Text 3 有一个 Smalltalk/X highlighting 包文件,由我自己在 BitBucket 托管。我主要为 Smalltalk 及其嵌入式 C 突出显示创建它。
首先,您可能使用的是stx 可执行文件,而不是stc。 stc 是smalltalk-to-C 编译器 的快捷方式。 stc 生成C 代码,然后可以由C 编译器 编译成目标文件,然后链接 带有最终的可执行文件(连同其他 smalltalk 类和运行时)。
smalltalk 或 stx 是一个启动器,可以执行 smalltalk 脚本或打开一个成熟的 IDE。如果您熟悉 Java,请考虑 stc 和 javac 和 smalltalk 或 stx 和 java。
您可以使用提供的名为 smalltalk 的启动器(*nix 的 bash 脚本和 windows 的批处理/powershell),它在末尾使用 stx.com,但提供了一些额外的功能。
使用smalltalk --help 查看命令行选项。
首先,我将从一个您可以使用的简单单线开始:
stx.com -I --quick --eval "Transcript showCR: 'A message on stdout on Transcript'
A message on stdout on Transcript
在 Windows 上,如果您使用 smalltalk,您将获得更多信息:
smalltalk -I --quick --eval "Transcript showCR: 'A message on stdout on Transcript'
"[INFO] PowerShell detected: ->TRUE<-.
"[INFO] The latest latest_powershell_version found: 5.1.16299.1004."
"[INFO] With the runtime being: v4.0.30319."
VERBOSE: [INFO] Manual switch detected - configuration is ignored
VERBOSE: [INFO] Executing asynchronously command: C:\prg_sdk\stx8-jv_swing\build\stx\projects\smalltalk\stx.com -I
--quick --eval "Transcript showCR: 'A message on stdout on Transcript'" | Out-null
VERBOSE: A message on stdout on Transcript
VERBOSE:
VERBOSE: [INFO] Exiting from PowerShell with code 0
VERBOSE: [INFO] End. Exiting correctly.
现在让我们转到您的脚本问题
一开始最好的方法是在 IDE 中创建一个类,然后从它里面做一个 fileOut。然后您将看到.st 文件应具有的正确结构。
我已经为您创建了一个简单的文件script.st(这与您在 IDE 的 fileOut 中获得的内容类似):
"{ NameSpace: Smalltalk }"
Object subclass:#MyClass
instanceVariableNames:'mainValue'
classVariableNames:''
poolDictionaries:''
category:''
!
!MyClass methodsFor:'accessing'!
mainValue
^ mainValue
!
mainValue: newValue
mainValue := newValue
! !
!MyClass methodsFor:'initialization & release'!
initialize
super initialize.
mainValue := 555.
! !
gc := MyClass new.
gc initialize.
Transcript showCR: gc mainValue.
你如何运行这样的脚本?
smalltalk --execute script.st
输出将是:555
如果你想编写没有“对象”的脚本(在 Smalltalk 中一切都是对象,但你没有在这里定义类)你可以做简单的transcript.st:
| mainValue |
mainValue := 555.
Transcript showCR: mainValue.
再次执行:smalltalk --execute transcript.st 得到相同的结果。