Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Error reported seems incorrect or unexpected


AutoFrank

Question

HI,

I'm reasonably sure I did't see this prior to 4.120

 

With the following code

Please login or register to see this code.

 I am getting the following error

 

Please login or register to see this attachment.

 

The problem is typo and I have one too many parenthesis (just after the if) 

It is reporting the correct line # but I thought that prior to 4.120, this would have been reported as something like "expected (  after blah' or 'expected then after blah'

 

Perhaps it was always there but it seems like a poor description for what was actually wrong in the code

 

Thoights

-f

 

Link to comment
Share on other sites

16 answers to this question

Recommended Posts

  • 0
30 minutes ago, AutoFrank said:

HI,

I'm reasonably sure I did't see this prior to 4.120

 

With the following code

Please login or register to see this code.

 I am getting the following error

 

Please login or register to see this attachment.

 

The problem is typo and I have one too many parenthesis (just after the if) 

It is reporting the correct line # but I thought that prior to 4.120, this would have been reported as something like "expected (  after blah' or 'expected then after blah'

 

Perhaps it was always there but it seems like a poor description for what was actually wrong in the code

 

Thoights

-f

 

Shouldn't you have a")"  after scoolStateMapping.No ? 

Link to comment
Share on other sites

  • 0

Quite Interesting. I agree with both of you. I expect a compiler error. Either removing the first parentheses or adding one before 'then' solves it. In Lua, the outer parentheses are not needed, in C they are mandatory. But that was not the question... Why doesn't the compiler bark? I don't know, but I've got a clue. The error refers to 'selfid' so this is not a scene, but part of a VD main loop... And this is somewhat special because a main loop runs every three seconds.

 

This is just a long excuse to say that i don't know. But if you insist, I'll see if I can explain... :-)

 

Link to comment
Share on other sites

  • 0
5 minutes ago, petergebruers said:

I expect a compiler error.

Compiler?!?

I thought, that lua is an interperter languge. Am i wrong?

Link to comment
Share on other sites

  • 0
Just now, Bodyart said:

Compiler?!?

I thought, that lua is an interperter languge. Am i wrong?

 

You are... confused, but that's no problem and I'll fix that :-)

 

The text you write is compiled, then it runs. It's really a "compiler". People sometimes say it's interpreted, because it is so easy to compile and run a piece of text that it resembles an interpreter. If you change the text, you will have to compile again (a true interpreter might allow self modifying code, but apart from being interesting, it's also awfully difficult to read and debug). Compilation on a modern CPU is so fast... For example, I ran a piece of code on my laptop and I got: "Program completed in 0.07 seconds". That's compilation + actual runtime. 

 

A quote from the Lua manual: "Although we refer to Lua as an interpreted language, Lua always precompiles source code to an intermediate form before running it."

 

The full page is  here:

 

Please login or register to see this link.

 

I'd like to quote an example of interpreter-like behaviour:

 

f = loadstring("i = i + 1")


f will be a function that, when invoked, executes i = i + 1:
    i = 0
    f(); print(i)   --> 1
    f(); print(i)   --> 2


"The loadstring function is powerful; it must be used with care. It is also an expensive function (when compared to its alternatives) and may result in incomprehensible code. Before you use it, make sure that there is no simpler way to solve the problem at hand."

 

I don't ever use "loadstring", but I do use its companion"dofile" (offline only, on an HC2 the command has been disabled).

Link to comment
Share on other sites

  • 0

Hi @AutoFrank,

 

For same error you get different debug error in VD and in scenes. Try same code in scene and you will get better description of error. This code is from VD isn't it?

Link to comment
Share on other sites

  • 0
9 minutes ago, Sankotronic said:

Hi @AutoFrank,

 

For same error you get different debug error in VD and in scenes. Try same code in scene and you will get better description of error. This code is from VD isn't it?

 

Thanks, you seem to agree with my post #3 :-) - but the question remains: why does this happen? I bet it has to do with how a "main loop" is actually invoked, as part of a larger construction. While a scene is a stand-alone Lua script. Also, the Lua version is different, but I don't think that explains it, I've made errors on any 5.X version and it works as expected :-D Where are the guys with a rooted and reverse engineered HC2, to answer this question?

Link to comment
Share on other sites

  • 0
  • Inquirer
  • 18 minutes ago, Sankotronic said:

    Hi @AutoFrank,

     

    For same error you get different debug error in VD and in scenes. Try same code in scene and you will get better description of error. This code is from VD isn't it?

     

    @Sankotronic

    @petergebruers

    @Bodyart

     

    Thanks for the input...

    Yes, the error is from a vd but it's from a button and not a main loop but I'm not sure the distinction matters.

    I'm trying to think back and I'm reasonably sure I'd have gotten a syntax related error (or what peter calls a compiler error) in previous versions of the fw....... but TBH not 100%

     

     

     

     

    Link to comment
    Share on other sites

    • 0
    16 minutes ago, AutoFrank said:

    (...) (or what peter calls a compiler error)(...)

     

    Yes, indeed, but "syntax error" is interchangeable here. I chose "compiler error", because I assume the script didn't run. Let me give 2 examples to illustrate "compiler" versus "runtime".

     

    This gives a compiler error:

    Please login or register to see this code.

    This is a runtime error:

     

    Please login or register to see this code.

    Actually, the red text in post #1 doesn't seem to match either of these. I'd swear I've seen this "line blah-blah-blah: 123" style of message before, but I can't remember where. I think it is only a part of an error message, and that error was caught (by "pcall?)" and only part of it was printed. It's a long shot.

     

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thanks Peter,

     

    A little more mystery from playing around with this one.....

     

    If I create a new vd and add in just the code in post 1

    Please login or register to see this code.

    I get the funny error

    Please login or register to see this attachment.

     

    If i remove all the local var declarations ad I don't need them to run this segment of code

     

    Please login or register to see this code.

    then I get the expected error

    Please login or register to see this attachment.

     

    so it's to do with the seflid declaration even though I'm not using it...

     

    vd with both buttons attached and should run on your systems

     

     

     

     

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0

    Intriguing. Can't test right now. If you find the time, can you try this: add a semicolon after every variable declaration. You probably know that I always tell they are not needed, except in some odd cases. In this case I'm just curious if it changes anything. All your locals seem to initialize by calling a function, so use parentheses. Just thinking aloud.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 1 hour ago, petergebruers said:

    Intriguing. Can't test right now. If you find the time, can you try this: add a semicolon after every variable declaration. You probably know that I always tell they are not needed, except in some odd cases. In this case I'm just curious if it changes anything. All your locals seem to initialize by calling a function, so use parentheses. Just thinking aloud.

     

    @petergebruers

     

    semi colons didn't make a difference as you expected.

     

    I reduced down the code even further to eliminate most of the functions and still get the error

    Please login or register to see this code.

    If i put the extra ( anywhere or remove the 'then' the weird error remains

    If I replace the for with a while loop the same happens

     

     

    Link to comment
    Share on other sites

    • 0

    Tnx for trying. Btw this is my approach when I have a similar problem. Divide the code in roughly two equal parts. Use a block comment to comment one part. If it compiles, you know that part contains the error. Then I split that part and repeat the procedure. Sort of 'binary search' on code.

    Edited by petergebruers
    Link to comment
    Share on other sites

    • 0
    10 minutes ago, petergebruers said:

    Tnx for trying. Btw this is my approach when I have a similar problem. Divide the code in roughly two equal parts. Use a block comment to comment one part. If it compiles, you know that part contains the error. Then I split that part and repeat the procedure. Sort of 'binary search' on code.

     

    Coding "gold"

    Link to comment
    Share on other sites

    • 0

    The ( after the if should be removed or add an other before then.

     

    Please login or register to see this code.

     

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 1 hour ago, petergebruers said:

    Tnx for trying. Btw this is my approach when I have a similar problem. Divide the code in roughly two equal parts. Use a block comment to comment one part. If it compiles, you know that part contains the error. Then I split that part and repeat the procedure. Sort of 'binary search' on code.

     

    @petergebruers

    @boerremk

    @Jamie mccrostie

     

    Thanks peter - That's similar to what I do but I use lots of single line comments but I like the block comments instead of lots of single ones so I might use that in future...

    This one was easy enough to find as the line number was accurate, it was just interesting to share as the error message was a bit odd

     

    good discussion - thanks everybody

     

     

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...