尝试为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
”创建'复合'布尔表达式时,编译失败。
那么,我如何在Lua中进行上述检查?也许根本不支持上面的C语法 - 我应该使用类似match的东西?
提前感谢您的回答,
干杯!
答案 0 :(得分:5)
以下对我来说很好:
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
答案 1 :(得分:3)
Pfffft ....语法错误 - 最后忘记了then
:
if fchars == "//" or fchars == "##" then
print "got it"
end
干杯!