Plugin: LuaView

LuaView is a simple plugin that puts all of your scene’s Lua scripts on a single page, making it easier to see the relationships between them, identify global variables and shared data, etc. The scripts are editable. The startup Lua is also displayed/editable.

This simple project was an interesting exercise. I almost got away with it having no Lua implementation whatsoever (all JavaScript), but alas, there was one thing I could not find in the JavaScript API (saving Startup Lua), so I implemented it as a custom Luup request. In any case, this is a very lightweight, single-instance plugin.

The source code and documentation for this project can be found in its Github repository.

As always, discussions and questions about this plugin in this thread, please.


VERSION HISTORY
2019-12-01: Release 1.6. Fix overly-aggressive whitespace removal. Forces sync of user_data between UI and Vera (on any firmware).

2019-01-20: Release 1.5. This version checks syntax of Luup code and reports any problems to the user.

2019-01-03: Release 1.4 loads ACE if it’s not loaded, so it offers a syntax-highlighting editor on UI7.

2018-11-11: Release 1.3. This version unifies the UI7 and ALTUI code and makes the decision on which interface to present (dumb textareas or fancy ACE editor) based on availability/resources.

2018-08-27: Release 1.2 is now available in the AltAppStore (only). This version addresses @jswim788’s excellent suggestion that it use the ACE editor familiar in other area of ALTUI. ACE does syntax highlighting and code checking.

2018-08-26: Release 1.0 is available in the Vera Plugin Maretplace; version 1.1, exclusively for openLuup, is available in the AltAppStore.

openLuup support? Thanks.

Well… OK. :slight_smile:

Took a little longer, because openLuup doesn’t do Vera Luup’s Lua encoding thing, so I had to add detection and exceptions for openLuup, but easy enough. In the AltAppStore.

Nicely done - thank you.

For bonus points, any chance of using the AltUI Lua code editor that is in the Lua Code Test window? That would be fantastic to see the syntax checker built in.

[quote=“jswim788, post:4, topic:199700”]Nicely done - thank you.

For bonus points, any chance of using the AltUI Lua code editor that is in the Lua Code Test window? That would be fantastic to see the syntax checker built in.[/quote]

I’ve added that as issue #1 on Github.

[quote=“rigpapa, post:5, topic:199700”][quote=“jswim788, post:4, topic:199700”]Nicely done - thank you.

For bonus points, any chance of using the AltUI Lua code editor that is in the Lua Code Test window? That would be fantastic to see the syntax checker built in.[/quote]

I’ve added that as issue #1 on Github.[/quote]

Issue #1 has now been addressed with the release of version 1.2 to the AltAppStore (applies to ALTUI only, available now). Per @jswim788’s excellent suggestion, this version uses the ACE editor when running under ALTUI, which gives you syntax highlighting and code validation.

Good work - it’s going well over here. Have already found some dusty old code, hiding in a dark corner.

Currently each editor box for each scene is about 8 lines high minimum by default. All my scenes (65 off) just contain one line of code. So lots of white space with all the edit boxes. Would it be possible to auto size the vertical, so it can shrink down to the number of lines code +1 and the auto scroll kicks in, if the box height reaches the current 8 lines?

It would be good if the scenes could be optionally sorted by scene id, as well as by the currently used scene name. Sort setting would persist.

[quote=“a-lurker, post:7, topic:199700”]Good work - it’s going well over here. Have already found some dusty old code, hiding in a dark corner.

Currently each editor box for each scene is about 8 lines high minimum by default. All my scenes (65 off) just contain one line of code. So lots of white space with all the edit boxes. Would it be possible to auto size the vertical, so it can shrink down to the number of lines code +1 and the auto scroll kicks in, if the box height reaches the current 8 lines?

It would be good if the scenes could be optionally sorted by scene id, as well as by the currently used scene name. Sort setting would persist.[/quote]

Are you using AltUI or UI7, @a-lurker?

In AltUI with FireFox & openLuup.

This is really nice. Thank you again. I can definitely gain some efficiency this way.

I do think it might be nice to have the startup Lua and the scene code on the same page. The reason is that it is easier to see the scene code and figure out what global functions and constants are needed and work on them in the same page. AltUI and openLuup.

There’s a state variable called AceOptions that you can put editor options into as a JSON object. For the moment, try this as a workaround: [tt]{ minLines: 2, maxLines: 8 }[/tt]

Yep that worked OK. Thanks.

I had to use quotes:

{ "minLines": 2, "maxLines": 8 }

else I got the “Can’t apply your custom AceOptions: SyntaxError: JSON.parse …”

[quote=“a-lurker, post:12, topic:199700”]I had to use quotes:

{ "minLines": 2, "maxLines": 8 }

else I got the “Can’t apply your custom AceOptions: SyntaxError: JSON.parse …”[/quote]

And that’s what I get for posting when I should be asleep. Sorry about that, but I’m glad you worked it out.

I’m pretty sure you can put any option you want there, including the theme. I went with a lighter theme than ALTUI’s by default because I have trouble reading the monokai color scheme on the dark background. But if you want it consistent with the rest of ALTUI, just add [tt]“theme”: “ace/themes/monokai”[/tt] to that list.

[quote=“jswim788, post:10, topic:199700”]This is really nice. Thank you again. I can definitely gain some efficiency this way.

I do think it might be nice to have the startup Lua and the scene code on the same page. The reason is that it is easier to see the scene code and figure out what global functions and constants are needed and work on them in the same page. AltUI and openLuup.[/quote]

OK. Question then: a-lurker also suggested sorting options. If I put the startup Lua on the same page with scene Lua, what would you expect from how it’s sorted? I’m thinking just pin it to the top/first position, and the scenes come after.

Yes, at the top… it is, after all, global to all the other scene code.

Yes, at the top. If I were greedy, I’d request that it be frozen like in Excel so that you can always see it and the scene you are working on, but that’s probably asking too much.

By the way I notice that openLuup is restarted after a scene change. I didn’t think that was necessary? Maybe it is.

Really? It doesn’t for me, and it’s not meant to.

Really? It doesn’t for me, and it’s not meant to.[/quote]

I don’t think it does for me either, but then, it restarts so fast I may not have noticed. I’m on my way to check as well…

Really? It doesn’t for me, and it’s not meant to.[/quote]

I don’t think it does for me either, but then, it restarts so fast I may not have noticed. I’m on my way to check as well…[/quote]

No, I’m not seeing any reloads when writing the scene data. I’m currently on 2018.08.05 development branch.

Maybe what you are thinking of is editing Startup Lua??

In this case, AltUI says:

"do you want to change Lua startup code ? if yes, it will generate a Lua reload, be patient… "

Vera does do a reload in this case (as in so many others) but openLuup does not.

© 2019 Vera Control Ltd., All Rights Reserved. Terms of Use | Privacy Policy