试图为Scite编写一个Lua脚本(比如lua-users wiki:Scite Comment Box),当我编写下面的代码时:
fchars = string.sub(line, 1, 3)
if fchars == "//" or fchars == "##"
print "got it"
end
Run Code Online (Sandbox Code Playgroud)
...编译失败了" attempt to call a string value
".
我尝试了不同的变体,例如:
assert(ktest = (("//" == fchars) or ("##" == fchars)))
Run Code Online (Sandbox Code Playgroud)
...在我看来,当我尝试使用逻辑运算符 " or
" 创建'复合'布尔表达式时,编译失败.
那么,我如何在Lua中进行上述检查?也许根本不支持上面的C语法 - 我应该使用匹配之类的东西?
提前感谢任何答案,
干杯!
以下工作对我来说很好:
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
Run Code Online (Sandbox Code Playgroud)