sdaau
sdaau

Reputation: 38619

Scite Lua: string comparison raises "attempt to call a string value"?

Trying to write a Lua script for Scite (something like lua-users wiki: Scite Comment Box), and when I write the following piece of code:

fchars = string.sub(line, 1, 3)

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

... the compilation fails with "attempt to call a string value".

I have tried different variants, such as:

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

... and it seems to me that compilation fails when I try to make a 'compound' boolean expression using the logical operator "or".

 

So, how would I do the above check in Lua? Maybe the C-like syntax as above is not supported at all - and I should use something like match instead?

 

Thanks in advance for any answers,
Cheers!

Upvotes: 2

Views: 9416

Answers (2)

John Ledbetter
John Ledbetter

Reputation: 14173

The following worked fine for me:

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

Upvotes: 5

sdaau
sdaau

Reputation: 38619

Pfffft.... syntax error - forgot then at end:

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

Cheers!

Upvotes: 3

Related Questions