arkts-sta-playground
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseArkTS-Sta Playground Runner
ArkTS-Sta Playground 运行器
Overview
概述
This skill runs ArkTS-Sta code using the ArkTS-Sta Playground HTTP API, providing fast and reliable code execution without browser automation.
本技能通过ArkTS-Sta Playground HTTP API运行ArkTS-Sta代码,无需浏览器自动化即可提供快速可靠的代码执行能力。
Quick Start
快速开始
Basic Usage
基础用法
Run an ArkTS-Sta file:
bash
python3 scripts/run_playground.py path/to/code.etsRun code directly as a string:
bash
python3 scripts/run_playground.py --code "let x: number = 42; console.log(x);"Get JSON output for programmatic parsing:
bash
python3 scripts/run_playground.py --json --code "console.log('Hello');"运行ArkTS-Sta文件:
bash
python3 scripts/run_playground.py path/to/code.ets直接运行字符串形式的代码:
bash
python3 scripts/run_playground.py --code "let x: number = 42; console.log(x);"获取JSON格式输出以便程序化解析:
bash
python3 scripts/run_playground.py --json --code "console.log('Hello');"Setup Requirements
环境搭建要求
Install Python dependencies:
bash
pip install -r scripts/requirements.txtRequired package:
requests>=2.31.0安装Python依赖:
bash
pip install -r scripts/requirements.txt所需依赖包:
requests>=2.31.0Usage Patterns
使用场景
Pattern 1: Quick Code Testing
场景1:快速代码测试
When testing ArkTS-Sta syntax or verifying code logic:
bash
python3 scripts/run_playground.py --code "
enum Numbers {
A = 10,
B = 2.57,
C = 0x2B7F,
D = -1.5,
E = 12
}
"测试ArkTS-Sta语法或验证代码逻辑时:
bash
python3 scripts/run_playground.py --code "
enum Numbers {
A = 10,
B = 2.57,
C = 0x2B7F,
D = -1.5,
E = 12
}
"Pattern 2: Batch Testing
场景2:批量测试
For testing multiple files:
bash
for file in test/*.ets; do
python3 scripts/run_playground.py --json "$file" > "results/$(basename $file .ets).json"
done测试多个文件时:
bash
for file in test/*.ets; do
python3 scripts/run_playground.py --json "$file" > "results/$(basename $file .ets).json"
doneHow It Works
工作原理
The script uses the HTTP API endpoint:
- Sends your ArkTS-Sta code to
https://arkts-play.cn.bz-openlab.ru:10443/compile - Receives compilation results and output
- Returns formatted results (success status, output, errors)
该脚本使用以下HTTP API端点:
- 将你的ArkTS-Sta代码发送至
https://arkts-play.cn.bz-openlab.ru:10443/compile - 接收编译结果和输出
- 返回格式化后的结果(成功状态、输出内容、错误信息)
API Endpoint
API端点
Base URL:
https://arkts-play.cn.bz-openlab.ru:10443/compileMethod: POST
Request:
json
{
"code": "your ArkTS-Sta code here"
}Response:
json
{
"output": "execution output or empty",
"error": "error message if compilation failed, null otherwise"
}基础URL:
https://arkts-play.cn.bz-openlab.ru:10443/compile请求方法: POST
请求体:
json
{
"code": "your ArkTS-Sta code here"
}响应体:
json
{
"output": "execution output or empty",
"error": "error message if compilation failed, null otherwise"
}Troubleshooting
故障排除
Connection issues
连接问题
If you get connection errors:
- Check internet connectivity
- Verify the API endpoint is accessible
- Check firewall settings
bash
undefined如果遇到连接错误:
- 检查网络连接
- 验证API端点是否可访问
- 检查防火墙设置
bash
undefinedTest connectivity
测试连接
curl -X POST https://arkts-play.cn.bz-openlab.ru:10443/compile
-H "Content-Type: application/json"
-d '{"code":"let x: number = 42;"}'
-H "Content-Type: application/json"
-d '{"code":"let x: number = 42;"}'
undefinedcurl -X POST https://arkts-play.cn.bz-openlab.ru:10443/compile
-H "Content-Type: application/json"
-d '{"code":"let x: number = 42;"}'
-H "Content-Type: application/json"
-d '{"code":"let x: number = 42;"}'
undefinedTimeout issues
超时问题
Increase timeout if the API is slow:
bash
python3 scripts/run_playground.py --timeout 60 path/to/code.ets如果API响应缓慢,可增加超时时间:
bash
python3 scripts/run_playground.py --timeout 60 path/to/code.etsSSL certificate errors
SSL证书错误
If you encounter SSL certificate issues, you may need to:
- Ensure your system's CA certificates are up to date
- Or modify the script to disable SSL verification (not recommended for production)
如果遇到SSL证书问题,你可能需要:
- 确保系统的CA证书是最新的
- 或者修改脚本以禁用SSL验证(不建议在生产环境中使用)
Common Use Cases
常见使用场景
Learn ArkTS Syntax
学习ArkTS语法
Test and explore ArkTS language features:
bash
python3 scripts/run_playground.py --code "
// Test union types
let value: string | number = 'hello';
value = 42;
console.log(value);
"测试并探索ArkTS语言特性:
bash
python3 scripts/run_playground.py --code "
// 测试联合类型
let value: string | number = 'hello';
value = 42;
console.log(value);
"Quick Prototype Verification
快速原型验证
Verify code logic before integrating into your project:
bash
python3 scripts/run_playground.py --code "
function calculateSum(a: number, b: number): number {
return a + b;
}
console.log('Sum:', calculateSum(10, 20));
"在集成到项目前验证代码逻辑:
bash
python3 scripts/run_playground.py --code "
function calculateSum(a: number, b: number): number {
return a + b;
}
console.log('Sum:', calculateSum(10, 20));
"Debug Code Snippets
调试代码片段
Find compilation errors in your code:
bash
undefined查找代码中的编译错误:
bash
undefinedRun with JSON output for programmatic checking
以JSON格式输出以便程序化检查
python3 scripts/run_playground.py --json problem.ets
python3 scripts/run_playground.py --json problem.ets
Check exit status
检查退出状态
if python3 scripts/run_playground.py code.ets; then
echo "Compilation successful"
else
echo "Compilation failed"
fi
undefinedif python3 scripts/run_playground.py code.ets; then
echo "编译成功"
else
echo "编译失败"
fi
undefinedScript Output
脚本输出
The script returns a JSON structure (with flag):
--jsonjson
{
"success": true,
"output": "Execution result here...",
"error": null,
"has_error": false
}Fields:
- : Boolean indicating if the API request succeeded
success - : Code output or compilation output
output - : Error message if compilation failed,
errorotherwisenull - : Boolean indicating if the code has compilation errors
has_error
使用参数时,脚本会返回如下JSON结构:
--jsonjson
{
"success": true,
"output": "Execution result here...",
"error": null,
"has_error": false
}字段说明:
- :布尔值,表示API请求是否成功
success - :代码输出或编译输出
output - :编译失败时的错误信息,否则为
errornull - :布尔值,表示代码是否存在编译错误
has_error
Example: Testing Enum with Floating Point
示例:测试包含浮点数的枚举
Test if enum with non-integer values causes errors:
bash
python3 scripts/run_playground.py --code "
enum Numbers {
A = 10,
B = 2.57,
C = 0x2B7F,
D = -1.5,
E = 12
}
"Expected result: Should fail with an error about enum values needing to be integers.
测试包含非整数值的枚举是否会引发错误:
bash
python3 scripts/run_playground.py --code "
enum Numbers {
A = 10,
B = 2.57,
C = 0x2B7F,
D = -1.5,
E = 12
}
"预期结果:应失败并提示枚举值必须为整数的错误。
Limitations
局限性
- Requires internet access to the API endpoint
- API rate limiting may apply
- Compilation output format depends on the API response
- 需要联网才能访问API端点
- API可能存在速率限制
- 编译输出格式取决于API响应
Tips for Efficient Usage
高效使用技巧
- Use JSON output for programmatic processing ()
--json - Batch test multiple files using shell loops
- Check exit codes in scripts for success/failure
- 使用JSON输出进行程序化处理(参数)
--json - 批量测试多个文件时使用Shell循环
- 检查退出码以判断脚本执行成功或失败