It is currently May 21st, 2024, 4:01 pm
Please tell me an example of luascript
-
- Posts: 105
- Joined: March 15th, 2024, 7:30 pm
Please tell me an example of luascript
Please tell me an example of luascript that erases the contents of a specific file. if this is possible. And also an example of writing to a file. I tried to understand how it works using examples here and in https://docs.rainmeter.net/manual/lua-scripting/ and didn’t understand anything and didn’t get any results
-
- Posts: 276
- Joined: December 28th, 2022, 9:30 pm
- Location: México
Re: Please tell me an example of luascript
I would use cmd/powershell for that instead, using a runcommand measure.Kotofanchik wrote: ↑April 3rd, 2024, 4:01 pm Please tell me an example of luascript that erases the contents of a specific file. if this is possible. And also an example of writing to a file. I tried to understand how it works using examples here and in https://docs.rainmeter.net/manual/lua-scripting/ and didn’t understand anything and didn’t get any results
Here you can find 2 commands to do it.
-
- Rainmeter Sage
- Posts: 16250
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Please tell me an example of luascript
It definitely is possible. For instance create the Script.lua file into the @Resources folder of your config (obviously you can use any valid name, just make sure to set the proper name in the [MeasureLuaScript] measure of yoru skin):Kotofanchik wrote: ↑April 3rd, 2024, 4:01 pm Please tell me an example of luascript that erases the contents of a specific file. if this is possible.
Code: Select all
function EmptyFile(file)
io.open(file,"w"):close()
end
Add the following function to the previously created Script.lua file, beside the already existing EmptyFile function:
Code: Select all
function WriteFile(file, stringTowrite)
filewrite = io.open(file, "w")
filewrite:write(stringTowrite)
filewrite:close()
end
If you did this, when you left click the meter you've added the above two options to, the appropriate file is emptied, while when you right click it, the Text to be written into the file text is written to the file.
Obviously if you simply right click the meter (without left clicking it first), the Text to be written into the file string is written to the file, without emptying it first.
Please let me know if you can't get any of the above functions to work.
-
- Posts: 105
- Joined: March 15th, 2024, 7:30 pm
Re: Please tell me an example of luascript
I won't be able to test it quickly. I'm slow to figure it out. Thanks for answers.
-
- Rainmeter Sage
- Posts: 16250
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Please tell me an example of luascript
Alright, I attach an installer, which installs an example skin (called ExampleLua\ExampleSkin.ini). If you install it, when Rainmeter restarts, you get a simple skin, showing a Left click to empty / Right click to write string. Check the content of the included @Resources\TextFile.txt file (this is the file which will be altered by the Lua script and at first it contains a Check this file string). If you left click the skin, the @Resources\TextFile.txt file is emptied. If you right click the string, you get written in the file the Welcome to Lua string, as written as the second parameter of the WriteFile(...) function, in the RightMouseUpAction option of the [MeterToWorkWithFile] meter of the skin.Kotofanchik wrote: ↑April 3rd, 2024, 5:44 pm I won't be able to test it quickly. I'm slow to figure it out. Thanks for answers.
Try to check all this, give it a few tries, alter the content of the skin and so on. If any question arises, feel free to come back and ask.
You do not have the required permissions to view the files attached to this post.
-
- Posts: 105
- Joined: March 15th, 2024, 7:30 pm
Re: Please tell me an example of luascript
Thank you. The finished skins are the best way for me to understand how things work.
-
- Rainmeter Sage
- Posts: 16250
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Please tell me an example of luascript
You're welcome. Check it and come back if any question arises.Kotofanchik wrote: ↑April 3rd, 2024, 6:59 pm Thank you. The finished skins are the best way for me to understand how things work.
-
- Posts: 105
- Joined: March 15th, 2024, 7:30 pm
Re: Please tell me an example of luascript
Yes, everything works, the file is written text and the text is erased. Thank you.
-
- Rainmeter Sage
- Posts: 16250
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Please tell me an example of luascript
Kotofanchik wrote: ↑April 3rd, 2024, 7:57 pm Yes, everything works, the file is written text and the text is erased. Thank you.
-
- Posts: 105
- Joined: March 15th, 2024, 7:30 pm
Re: Please tell me an example of luascript
For the future, is it possible to read text in a file located not in the Rainmeter folders? In the browser cache for example?