It is currently March 28th, 2024, 7:21 pm

Change in Lua scripting to allow dofile to be used

Changes made during the Rainmeter 4.0 beta cycle.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Change in Lua scripting to allow dofile to be used

Post by jsmorley »

We have changed the context of each Lua measure in your skins to be entirely local to the individual measure, to eliminate problems with defined variables or functions "bleeding" between skins when they were defined in the Initialize() function.

This has allowed us to support the use of the Lua dofile functionality, allowing you to for instance have a "toolkit" of Lua functions that you can easily share between skins in your current root config folder.
Using dofile

The dofile function can be used to include libraries or other snippets of Lua code. You must specify a full path to the dofile, using the syntax dofile('C:\PathToDoFile\SomeLua.lua'). Use GetVariable function if you want to use the #@# variable shortcut to the @Resources folder for the current config, or MakePathAbsolute if you want to have the .lua file be relative to the current skin folder.

Code: Select all

function Initalize()
	dofile(SKIN:GetVariable('@')..'MyDoFiles\\toolkit.lua')
	dofile(SKIN:MakePathAbsolute('toolkit.lua'))
end
Note: While a dofile you call can be anywhere on your system, be aware that if you do not put the dofile .lua file somewhere in the path to the current config, you won't be able to distribute it with your skin as a .rmskin package. A .rmskin package can only distribute the contents of a single root config folder.
You can view dofile as very similar in Lua to what @Include does in a skin...

Here is an example:
LuaDofile_1.0.rmskin
You do not have the required permissions to view the files attached to this post.
User avatar
raiguard
Posts: 660
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: Change in Lua scripting to allow dofile to be used

Post by raiguard »

YES! Thank you! This is exactly what I was waiting for!

Now to redo the past month's worth of work to take advantage of this! :D
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017