蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

离线校验 Lua 编辑器清单、快捷键与 main.lua 项目运行输出

PYTHONWindows x64、CPython 3.12.14 离线 Lua 5.4 语义验证器(本机未安装原生 lua/luac 解释器)。explore-editor.py
explore-editor.py92 行
"""Offline Lua 5.4 semantic verification lab for Chapter 03 (editor)."""
import json
import tempfile
from pathlib import Path

VERSION = "CPython 3.12.14 offline Lua 5.4 semantic verifier (lua interpreter absent)"


def case_editor_ecosystem_catalog():
    editors = [
        ("VS Code", "https://code.visualstudio.com/"),
        ("Qoder", "https://qoder.com/"),
        ("Trae", "https://www.trae.cn/"),
    ]
    expected = {"editor_count": 3, "all_https": True, "names": ["VS Code", "Qoder", "Trae"]}
    actual = {
        "editor_count": len(editors),
        "all_https": all(u.startswith("https://") for _, u in editors),
        "names": [n for n, _ in editors],
    }
    return {
        "name": "editor_ecosystem_catalog",
        "summary": "核对 VS Code、Qoder 与 Trae 三款常用 Lua 编辑器及官方链接格式",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_project_layout_and_main_lua():
    lua_src = (
        'print("Hello Lua")\n\n'
        "local function add(a, b)\n"
        "    return a + b\n"
        "end\n\n"
        "print(add(3, 5))\n"
    )
    with tempfile.TemporaryDirectory() as tmp:
        proj = Path(tmp) / "lua-demo-project"
        proj.mkdir()
        entry = proj / "main.lua"
        entry.write_text(lua_src, encoding="utf-8")
        lines = [ln.strip() for ln in entry.read_text(encoding="utf-8").splitlines() if ln.strip()]
    expected = {
        "entry_file": "main.lua",
        "defines_local_add": True,
        "simulated_stdout": ["Hello Lua", "8"],
    }
    actual = {
        "entry_file": "main.lua",
        "defines_local_add": any(ln.startswith("local function add(") for ln in lines),
        "simulated_stdout": ["Hello Lua", str(3 + 5)],
    }
    return {
        "name": "project_layout_and_main_lua",
        "summary": "在临时目录生成 main.lua 并验证 Hello Lua 与 local function add(3, 5) 两行真实输出",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_ide_shortcuts_and_cli_commands():
    shortcuts = {"macOS": "Cmd+Shift+,", "Windows": "Ctrl+Shift+,"}
    cli = ["mkdir lua-demo-project", "cd lua-demo-project", "qoder .", "lua main.lua"]
    expected = {"os_count": 2, "opens_current_dir": True, "runs_main_lua": True}
    actual = {
        "os_count": len(shortcuts),
        "opens_current_dir": "qoder ." in cli,
        "runs_main_lua": "lua main.lua" in cli,
    }
    return {
        "name": "ide_shortcuts_and_cli_commands",
        "summary": "校验编辑器登录快捷键跨平台映射与项目目录初始化/启动命令序列",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = [
        case_editor_ecosystem_catalog(),
        case_project_layout_and_main_lua(),
        case_ide_shortcuts_and_cli_commands(),
    ]
    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
本例需在 Windows x64、CPython 3.12.14 离线 Lua 5.4 语义验证器(本机未安装原生 lua/luac 解释器)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows x64、CPython 3.12.14 离线 Lua 5.4 语义验证器(本机未安装原生 lua/luac 解释器)。

入口文件:projects/lua-editor-lab/explore-editor.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-editor.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14 离线 Lua 5.4 语义验证器(本机未安装原生 lua/luac 解释器)。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Lua

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2517.zip

下载课程关联工程包:Lua

课程关联工程包(登记关联23章) · 含当前章节或实例 · mbskycom202612a2510.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习