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

离线校验本机 Lua 工具链状态、首个 Hello World 输出与核心特性模型

PYTHONWindows x64、CPython 3.12.14 离线 Lua 5.4 语义验证器(本机未安装原生 lua/luac 解释器)。explore-tutorial.py
explore-tutorial.py110 行
"""Offline Lua 5.4 semantic verification lab for Chapter 01 (tutorial)."""
import json
import re
import shutil

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


def case_toolchain_absence_probe():
    bins = {k: shutil.which(k) for k in ("lua", "lua5.4", "luac", "luajit", "luarocks")}
    expected = {
        "lua_found": False,
        "luac_found": False,
        "luarocks_found": False,
        "offline_mode": True,
    }
    actual = {
        "lua_found": bins["lua"] is not None or bins["lua5.4"] is not None,
        "luac_found": bins["luac"] is not None,
        "luarocks_found": bins["luarocks"] is not None,
        "offline_mode": all(v is None for v in bins.values()),
    }
    return {
        "name": "toolchain_absence_probe",
        "summary": "如实探测本机 lua/luac/luarocks 可执行文件,确认当前处于离线语义验证环境",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_hello_world_print_semantics():
    src = 'print("Hello World!")\n'
    m = re.match(r'^print\("([^"]*)"\)\s*$', src.strip())
    output = (m.group(1) + "\n") if m else ""
    expected = {
        "extension": ".lua",
        "call_target": "print",
        "stdout": "Hello World!\n",
    }
    actual = {
        "extension": ".lua",
        "call_target": "print" if m else "",
        "stdout": output,
    }
    return {
        "name": "hello_world_print_semantics",
        "summary": "校验首个 .lua 脚本中 print(\"Hello World!\") 的调用语法与精确标准输出",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_lua_core_feature_model():
    paradigms = ["procedural", "functional", "data-driven", "prototype-oop"]
    universal_ds = {"array": "table", "hash_map": "table", "set": "table", "object": "table"}
    expected = {
        "origin_year": 1993,
        "implementation_lang": "ISO C",
        "single_compound_type": "table",
        "paradigm_count": 4,
    }
    actual = {
        "origin_year": 1993,
        "implementation_lang": "ISO C",
        "single_compound_type": next(iter(set(universal_ds.values()))),
        "paradigm_count": len(paradigms),
    }
    return {
        "name": "lua_core_feature_model",
        "summary": "核对 Lua 起源年份、标准 C 实现、table 统一数据结构与多范式特性",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_lua_application_domains():
    domains = [
        "game-scripting",
        "embedded-app-extension",
        "web-nginx-openresty",
        "database-plugin",
        "security-ids",
    ]
    expected = {"domain_count": 5, "supports_c_host_embedding": True}
    actual = {"domain_count": len(domains), "supports_c_host_embedding": "embedded-app-extension" in domains}
    return {
        "name": "lua_application_domains",
        "summary": "校验 Lua 在游戏、嵌入式扩展、Web、数据库插件及安全系统中的典型定位",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = [
        case_toolchain_absence_probe(),
        case_hello_world_print_semantics(),
        case_lua_core_feature_model(),
        case_lua_application_domains(),
    ]
    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-tutorial-lab/explore-tutorial.py

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

下载课程关联工程包:Lua

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

下载课程关联工程包:Lua

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

搜索教程、工具与资讯

热门搜索

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

欢迎登录蓝色天空网

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