【问题标题】:VS Code / Lua: handling of Cpp-directivesVS Code / Lua:处理 Cpp 指令
【发布时间】:2022-01-18 17:01:46
【问题描述】:

我正在使用 C 预处理器在 Lua 中获取条件代码、代码包含和实数常量。不幸的是,VS-Code / Lua 对 lua 代码中的 #-directives 感到困惑。

有没有办法以某种方式从 lua 扩展的解析中排除这些行?

【问题讨论】:

    标签: visual-studio-code lua


    【解决方案1】:

    由于您已经在使用外部工具,我只需将 # 替换为 --# 并再次对其进行预处理:

    test.lua:

        --# if defined(TEST)
        print("test defined:", TEST)
        --# else
        print("test not defined")
        --# endif
    
    
    ❯ 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
    

    使用 Better Comments 扩展名并定义要突出显示的“#”可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 2016-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 2020-05-28
      • 1970-01-01
      • 2021-10-21
      相关资源
      最近更新 更多