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


Recommended Posts

Posted

I use this editor for my LUA programming, works with Windows, Linux and OSX

 

Please login or register to see this link.

 

 

Posted

Hi Johnny,

 

I checked the editor out. I see it can handle a lot of programming languages, also json, but I don't see LUA in the list.......

Posted

Notepad++ as well does LUA

 

Second that. Notepad ++ works well.

Posted

I used notepad++, but I change for Sublime Text 2

Posted

ZeroBrane Studio Lua IDE used here

Posted

Thanks for pointing us to another fine tool to add to our toolkit. I'd like to point out that ZeroBrane comes with the Lua interpreter, so you can actually write and run some code. Of course, it doesn't support "fibaro:" so it's restricted to generic code, unless you write the "fibaro:" functions yourself.

Please login or register to see this image.

/emoticons/default_icon_smile.gif" alt=":-)" /> I actually did that (like "fibaro:debug" does a "print") so I can run/simulate a scene to some extent. It's work in progress. When I see a Lua script on the forum, I try to simulate it and add code to my simulator until I can debug... One other editor, and certainly a "rising star", is "Atom".

Posted

 

Using Atom for a while now and i love it

Please login or register to see this image.

/emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

Posted

Thanks for pointing us to another fine tool to add to our toolkit. I'd like to point out that ZeroBrane comes with the Lua interpreter, so you can actually write and run some code. Of course, it doesn't support "fibaro:" so it's restricted to generic code, unless you write the "fibaro:" functions yourself.

Please login or register to see this image.

/emoticons/default_icon_smile.gif" alt=":-)" /> I actually did that (like "fibaro:debug" does a "print") so I can run/simulate a scene to some extent. It's work in progress. When I see a Lua script on the forum, I try to simulate it and add code to my simulator until I can debug... One other editor, and certainly a "rising star", is "Atom".

 

I just installed ZeroBrane, can you explain how you wrote the fibaro:debug function? 

 

I like the idea of being able to partially test code before running it live, but I can see it being a lot of work to create all (or at least the most commonly used) fibaro functions

Posted

I just installed ZeroBrane, can you explain how you wrote the fibaro:debug function? 

 

I like the idea of being able to partially test code before running it live, but I can see it being a lot of work to create all (or at least the most commonly used) fibaro functions

I surely want to share how that works. I also would share the complete code (of my simulator), but if I posted it here, I would have to support it. Because I am still tuning/tinkering and sometimes trying out another approach, supporting it would be an impossible task. To give an example, you have to simulate how a "motion sensor" gets triggered. Or, how many Watt a Wall plug reports when it is switched on. Currently, I use a table with possible values, but that is too limited... The part that simulates http request is *very* limited at the moment. Anyway here's the "debug" code:

 

Please login or register to see this code.

Here's an example thats a little more complex:

 

Please login or register to see this code.

This function returns "autostart" if you don't do anything in particular. But for some users, I need another sourceTrigger. That is what the "simData" is about:

 

Please login or register to see this code.

Next level up in complexity, is to allow a function call to return different values for every call. For example:

 

Please login or register to see this code.

I use some sorcery-code (pun intended) to iterate over stuff, that's why Date/Time sits at the same level as device simulation. We're now talking about a total of roughly 100 lines of code to make this work.

 

Please login or register to see this code.

The "simData.devices.Date.value" part is the table I've defined, but what is the "iter()" part? It's short for "iterator" and it's a function that is generated to fetch the next value in the array, then wrap. I cannot show the code for this function because it isn't there. There is code that generates the function. This is what they mean when they say "Lua has first class functions", meaning they are as flexible as variables.

This is an example that shows how difficult it is (nearly impossible) to get a perfect simulation. My os.date function only handles the argument types "%H:%M" and "*t". Anything else fails. But the beauty of programming is that nobody stops me from implementing a different argument, or rewrite this function. I probably have to, because the "*t" argument doesn't use the array, so that's a really bad and confusing implementation.

BTW you need to simulate, fibaro, net, Net, json and os, to be able to debug the most basic stuff. The os.date is needed to debug scripts that

Nevertheless, I hope this may inspire you to toy with ZeroBrane...

I hope jompa68 doesn't find this too much off-topic. It's about editing Lua in a broad sense, isn't it?

Have fun!

  • Like 1
  • Topic Author
  • Posted

     

    I hope jompa68 doesn't find this too much off-topic. It's about editing Lua in a broad sense, isn't it?

    Have fun!

     

     

    No, no not at all. Your help here on the forum and all the code you share is on a completely different level than the rest of us.

    Cheers m8 

    Please login or register to see this image.

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

    Posted

    OMG! That is on another level. You definitely deserve the rating of "I am the Matrix" when it comes to coding LUA!

     

    Thanks for sharing. I am not sure I have the time to do what you are doing, but good luck with it.

    Join the conversation

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

    Guest
    Reply to this topic...

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