Have one skin, use a lua script to write new measures into another skin?

Discuss the use of Lua in Script measures.

Have one skin, use a lua script to write new measures into another skin?

April 5th, 2017, 3:05 pm
   [5 posts]

Looking to create a setup program for my skin. want to make it so the user can select a few options, and a .ini file will be created for them with their chosen settings and meters based on their selections. is this possible to do with skins and lua?

note: its not really something i can just do with a skin editing entries in the variables.ini either. its basically taking a set of options, and constructing a skin via templates. using measures, and meters, in specific ways. something a skin couldn't really do very easily. i'd like the skin to generate a string describing the skin (which should be fairly simple to do) and then have the lua file take that string and construct the skin by converting the string into an array of instructions... that part i know i can do. the concern is both, passing the string to lua...and saving the text document. I'm not really sure how rainmeter and lua work in that regard.
User avatar

Re: Have one skin, use a lua script to write new measures into another skin?

April 5th, 2017, 3:28 pm
Developer   [15494 posts]

Certainly possible, but with a few caveats.

1) The .ini file must already exist, otherwise it won't be seen by Rainmeter when it is created by the Lua script, unless a full refresh of Rainmeter is forced with a bang, and that is likely to to pull the rug out from under things.

2) Lua will ONLY read ANSI / UTF-8 w/o BOM files, which means you won't be able to use any Unicode characters at all in what you write. Rainmeter won't work with UTF-8 w/o BOM files that contain any Unicode characters. While ANSI and UTF-8 are exactly the same thing as long as only characters from the ASCII character set are used, (decimal 1-255) any introduction of characters outside that range will be treated at UTF-8, and Rainmeter will hate it.

So it's a conundrum if you want any Unicode. While you can create the .ini file as UTF-16 Little Endian to start with, which Rainmeter is fine with, you then won't be able to read that file at all in Lua. You can "recreate" the file with the Lua script, avoiding reading it, but then you have to embed the character sequence ÿþ as the first thing you write. https://en.wikipedia.org/wiki/Byte_order_mark#UTF-16 That will work, but then be aware you can't ever read that file again in Lua.

So with those issues in mind, it seems to me you could:

Have the user select whatever options you want in Skin A. Have that skin execute a Lua script that:

1) Reads variables or measure values as needed from the calling skin (Skin A) and do whatever evaluation you want on those results.

2) Open an existing Skin B .ini file, in it's own subfolder. (It can't be in the same folder as Skin A)

3) Using a write method of "replace entire file", write whatever you want to the .ini. Again, be careful that you consider if you need to just write the file as ANSI encoding, but with NO Unicode characters, or as UTF-16 Little Endian. If you want to read the file and just make changes or additions to it, then you are very constrained indeed. The file MUST be ANSI encoded to start with, with NO Unicode characters in it, and any changes or additions you make must not introduce any Unicode characters.

4) Close the file and send a bang to Rainmeter using !ActivateConfig to load it. If it is already running, just send a !Refresh bang to the changed .ini file's config, to refresh it with the changes.


Return to “Lua Scripting”

Who is online

Users browsing this forum: No registered users and 2 guests