在 VS Code 中運行 Squirrel 語言編寫的?.nut
?程序,需要先配置 Squirrel 運行環境并安裝相關插件,具體步驟如下:
一、安裝 Squirrel 解釋器
Squirrel 程序需要通過其官方解釋器?squirrel
?或?sq
?執行,首先需要安裝解釋器:
- Windows 系統:
- 從 Squirrel 官方網站(squirrel-lang.org)下載源碼
- 用vs2010打開C:\Users\think\Downloads\squirrel_3_2_stable\squirrel3\squirrel.dsw
- 編譯生成sq.exe
- ?
sq.exe
(解釋器)的目錄添加到系統環境變量?Path
?中
- 從 Squirrel 官方網站(squirrel-lang.org)下載源碼
- Linux/macOS 系統:
- 可通過源碼編譯(官網下載源碼后執行?
make
?和?make install
) - 部分 Linux 發行版可通過包管理器安裝(如?
sudo apt-get install squirrel
)
- 可通過源碼編譯(官網下載源碼后執行?
二、在 VS Code 中配置運行環境
-
安裝 Squirrel 語法高亮插件:
- 打開 VS Code,進入擴展面板(Ctrl+Shift+X)
- 搜索并安裝?Squirrel?插件(通常選擇下載量較高的,如 S
quirrel Language Supports
件),用于代碼高亮和語法提示,
-
配置任務運行器(tasks.json):
- 打開?
.nut
?文件所在的項目文件夾 - 按?
Ctrl+Shift+P
?打開命令面板,輸入?Tasks: Configure Task
?并選擇?Create tasks.json file from template
- 選擇?
Others
?模板,替換內容為:
json
{"version": "2.0.0","tasks": [{"label": "Run Squirrel Script","type": "shell","command": "sq.exe", // 或 "squirrel",根據實際解釋器命令調整"args": ["${file}"], // 運行當前打開的 .nut 文件"group": {"kind": "build","isDefault": true},"problemMatcher": []}] }
- 打開?
三、運行?.nut
?程序
- 在 VS Code 中打開要運行的?
a.nut
?文件 - 按?
Ctrl+Shift+B
?執行配置好的任務,即可在終端中看到程序運行結果 - 若需傳遞參數,可在?
tasks.json
?的?args
?數組中添加,例如:["${file}", "param1", "param2"]