VS Code / Lua:处理 Cpp-directives

我正在使用 C 预处理器在 Lua 中获取条件代码、代码包含和真实常量。不幸的是,VS-Code / Lua 在解析 Lua 扩展时会对 #-directives 产生混淆。

是否有一种方法可以从解析 Lua 扩展的过程中排除这些行呢?

原文链接 https://stackoverflow.com/questions/70364882

点赞
stackoverflow用户5688146
stackoverflow用户5688146

由于您已经在使用外部工具,我建议把#替换为--#,然后再进行一次预处理:

test.lua:

    --# 如果定义了(TEST)
    print("test defined:", TEST)
    --# 否则
    print("test not defined")
    --# 结束

❯ cat test.lua | sed -r 's:--#:#:g' | gcc -E -P -xc - | luajit
test not defined

❯ cat test.lua | sed -r 's:--#:#:g' | gcc -E -P -DTEST=42 -xc - | luajit
test defined:   42

建议使用更好的注释扩展程序,并将#定义为高亮显示。

enter image description here

2022-01-17 11:47:00