Scite Lua:字符串比较引起“尝试对字符串值进行调用”错误?

尝试编写一个 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)))

... 我觉得当我尝试使用 逻辑运算符or” 时,在我试图组成“复合”的布尔表达式时编译失败。

那么,在 Lua 中如何进行上述检查呢?也许上面类似 C 语言的语法完全不受支持 - 我应该使用类似 match 这样的方法呢?

提前感谢任何答案,

谢谢!

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

点赞
stackoverflow用户277826
stackoverflow用户277826

Pfffft….语法错误——忘了在结尾加上then

if fchars == "//" or fchars == "##" then
  print "得到它了"
end

干杯!

2010-10-27 19:20:01
stackoverflow用户130641
stackoverflow用户130641

以下对我有效:

line = "//thisisatest"

fchars = string.sub(line, 1, 2) -- 我假设你是指1,2,因为//和##仅有2个字符长

if fchars == "//" or fchars == "##" then -- 你漏掉了"then"
   print("明白了!")
end
2010-10-27 19:23:10