It is currently April 20th, 2024, 12:24 pm

Using Lua to create computer specific skins

Discuss the use of Lua in Script measures.
Zinsho
Posts: 7
Joined: February 24th, 2011, 10:14 pm

Using Lua to create computer specific skins

Post by Zinsho »

I don't know if anyone has posted this yet but Lua can be used to generate skins.

I was curious about whether it could when looking at how Lua could be used with Rainmeter the other day, so I created a skin simply to test the theory.

Attached is the skin I came up with. Since I have a access to a few computers with different numbers of CPUs I was able to test it to make sure it worked.

When it runs it uses Lua to create a CPU meter with bars for every processor, automatically scaling it to the number of CPUs.

It isn't overly size-efficient (The Lua Script is as large as the initial .ini + an .ini for a i7 (8 cores reported)), however it was simply a proof of concept.

edit: Updated skin. I realized I'd left it with a static path when loading the generated skin, it won't work as it was. Reuploaded with path as a variable to match current location.
You do not have the required permissions to view the files attached to this post.
Last edited by Zinsho on February 25th, 2011, 1:33 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Using Lua to create computer specific skins

Post by jsmorley »

Sure. The thing you have to be cautious about if you are using Lua to write to .ini files is that you of course have to refresh the skin for it to "see" the new meters or measures. So if the call to the Lua code that creates them is in the skin, you risk an endless loop. As long as you think through how you are going to kick it off an where, no reason why you can't open and write to a .ini or .inc file in Lua.

I have not looked at your skin, but one thing in general about .lua vs .ini is that the capabilities to use for-next / do-while loops in Lua do offer some ways to shorten the amount of sheer "code" you need to accomplish some things.

There is a lot you can do with Lua in Rainmeter. There is also a lot you can't do. The current implementation we have, while powerful, is limited. As long as you wrap your head around what it does and doesn't allow, it can be a great tool.
Zinsho
Posts: 7
Joined: February 24th, 2011, 10:14 pm

Re: Using Lua to create computer specific skins

Post by Zinsho »

Retested the RM Skin on another computer this morning and noticed a small mistake in the Lua code.
I'd initially hard-coded the path to the new skin in [!RainmeterActivateConfig]

I used a slightly different path for testing to avoid cluttering my Skins folder and it was trying to load that file, rather than the one it created.


As to the endless loop, there are a few ways around it, strangely enough a high refresh rate (10,000 seconds) did not prevent Rainmeter from freezing.

One way around it is to pre-create the desired files, since Rainmeter already knows they're you only have to activate. A second way I tested while fixing the path this morning was to write back directly to the ini file I read from then [!RainmeterRefresh]. Of course that only works once, but the moment you change the content of the file it stops calling Lua so you no longer have any chance of a loop.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Using Lua to create computer specific skins

Post by jsmorley »

Zinsho wrote: One way around it is to pre-create the desired files, since Rainmeter already knows they're you only have to activate. A second way I tested while fixing the path this morning was to write back directly to the ini file I read from then [!RainmeterRefresh]. Of course that only works once, but the moment you change the content of the file it stops calling Lua so you no longer have any chance of a loop.
Both good approaches.
User avatar
santa_ryan
Posts: 397
Joined: June 22nd, 2010, 4:11 am

Re: Using Lua to create computer specific skins

Post by santa_ryan »

Another option is to do this

Put a variable

E.G. Update_On_Next_Refresh=1/0

and then a calc in which if the variable is 1 it calls the lua and updates the .ini and when its 0 the calc does nothing.

It would allow end users to update on command, if for instance they transfer the skins to their laptop (which i frequently do), and also allow them to reupload it if someone asks about it (though i would be cautious with how you do your Credits so they can't just easily replace your name)
I have three rules when I'm trying to help you.
  • Don't get mad when you don't understand something
  • Be VERY specific with what you ask for.
    The more specific you are, the higher the quality of support you receive.
  • Do not just copy and paste what I put in examples and come back saying it doesn't work.
    It does work, but I purposely left blanks that you need to fill for your specific needs.