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

If only we had proper Lua global variables


Question

Posted

If only global variables were available. Why not?

Please login or register to see this code.

7 answers to this question

Recommended Posts

  • 0
Posted

Not 100% sure what you are after? The time it takes to write to the global variable, or?

  • 0
  • Inquirer
  • Posted

    You can not store lua reference in a Fibaro style global variable. But proper lua state is not maintained across instances of a scene.

    The setTimeout(lua state, int). Passes the state as a hidden parameter.

    Now if when a new instance of a scene was created it is given the state of the instances running we would have global across instances of the same scene. So

    Please login or register to see this code.

    Would not be maintained as it would be scene instance environment specific but

    Please login or register to see this code.

    Would be

    So in my example the ref to the first timeout woul be available to a second instance of the scene that could cancel it.

    It would be a matter of on creation of a new instance of a scene passing the state shared by current instances to the new instance.

    I can create a plugin to do this generic turnoff after delay but it would be more flexible from a scene

    • 0
    Posted

    I'd say a form of message passing between scenes or scene instances (not counting setglobalvariable) would allow for cleaner code. I'm experimenting with a different usage pattern: create a main scene that does state detection and a slave scene that does tiling and use killscene to abort the timer. It works, but is doesn't look nice.

    • 0
  • Inquirer
  • Posted

    Hi,

    Yes that is what I put in a couple of years ago. The logic here is for if the machine is switched on off and then on again so that the counter is restarted. Similar idea though.

    master

    Please login or register to see this code.

    slave

    Please login or register to see this code.

    Was wanting to tidy it up.

    Do you think killing a scene that has a setTimeout registered is safe? I think I may leave as is.

    • 0
    Posted
    The logic here is for if the machine is switched on off and then on again so that the counter is restarted.

    Yes, that is quite similar to what I am trying now. I see no real objection to starting/killing scenes. I am also not religiously against splitting up code over 2, 3 or more scenes. But I share with this "uneasy feeling":

    Do you think killing a scene that has a setTimeout registered is safe?

    Well... I found out that when your scene has no more work to do, except for some setTimout job, it is still running. It will die only when the function registered with the setTimout exits. But that of course doesn't guarantee that cleanup of aborted scenes is working.

    You know what? This calls for a HC2 torture test!

    Please login or register to see this image.

    /emoticons/default_icon_cool.gif" alt="8-)" /> I'll do some experiments and I'll try to answer your question...

    • 0
  • Inquirer
  • Posted

    Yes I noticed a new property killable so I am not surprised that it does not die. Think I will leave them with sleep as I know that is safe.

    I think it is plugin time to make it tidy but that will have to wait for a while.

    • 0
    Posted

    As promised... a simple stress test

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    Please login or register to see this link.

    Didn't want to hijack your thread.

    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...