代码之家  ›  专栏  ›  技术社区  ›  sdaau

Scite Lua:字符串比较引发“尝试调用字符串值”?

lua
  •  2
  • sdaau  · 技术社区  · 14 年前

    尝试为Scite编写Lua脚本(类似于 lua-users wiki: Scite Comment Box ,当我写下以下代码时:

    fchars = string.sub(line, 1, 3)
    
    if fchars == "//" or fchars == "##" 
      print "got it"
    end 
    

    …编译失败,原因是“ attempt to call a string value “。

    我尝试过不同的变体,例如:

    assert(ktest = (("//" == fchars) or ("##" == fchars)))
    

    …在我看来,当我尝试使用 logical operator or “。

    那么,我该如何办理上述手续?也许上面的类C语法根本不受支持-我应该使用类似的 match 相反?

    事先感谢您的回答,
    干杯!

    2 回复  |  直到 14 年前
        1
  •  5
  •   John Ledbetter    14 年前

    以下对我来说很好:

    line = "//thisisatest"
    
    fchars = string.sub(line, 1, 2) -- I assume you meant 1,2 since // and ##
                                    -- are only 2 characters long
    
    if fchars == "//" or fchars == "##" then -- you're missing 'then'
       print("got it!") 
    end
    
        2
  •  3
  •   sdaau    14 年前

    pfffft….语法错误-忘记 then 结束时:

    if fchars == "//" or fchars == "##" then
      print "got it"
    end 
    

    干杯!