Lua Scripting スクリプティングを取る
Rainmeter has the ability to load and execute scripts in Lua, a functional programming language. Rainmeter includes the Lua 5.1 standard libraries, which encompass a variety of powerful features.Rainmeterは、関数型プログラミング言語であるLuaでスクリプトを読み込んで実行することができます。Rainmeterには、Lua 5.1標準ライブラリが含まれています。これには、さまざまな強力な機能が含まれています。
A script refers to a set of Lua functions that is associated with a script measure. These functions may be executed when the skin loads, when it updates, or on command.スクリプトが関連付けられているLuaの関数のセットを指すスクリプト尺度。これらの機能を実行することができるとき、スキンの負荷、それはときに更新、またはコマンドで。
This page details the Rainmeter-specific modifications and new functions that have been added to Rainmeter's built-in Lua environment. More documentation for Lua itself is available at:このページでは、Rainmeterに組み込まれているLua環境に追加された、Rainmeter固有の修正と新機能について詳しく説明します。Lua自体のためのより多くのドキュメンテーションは以下で利用可能です:
- Lua 5.1 Reference ManualLua 5.1リファレンスマニュアル
- Lua TutorialLuaチュートリアル
- Learning LuaLuaを学ぶ
- Programming in Lua by Roberto IerusalimschyRoberto Ierusalimschyによる Luaでのプログラミング
The rest of this page assumes a basic knowledge of the Lua language.このページの残りの部分はLua言語の基本的な知識を前提としています。
Script Measureスクリプトメジャー
The script measure is used to load a Lua script from a file and interface with the script. The script file must be a text file, and typically has the extension .lua
.スクリプトメジャーは、ファイルからLuaスクリプトをロードし、そのスクリプトとやり取りするために使用されます。スクリプトファイルはテキストファイルで、通常は拡張子を持っていなければなりません.lua
。
Much like plugin measures, each script measure creates a separate instance of its script. This means that a skin can have any number of scripts loaded simultaneously—even from the same script file. (The order in which scripts are executed is determined by the measure order.) "Global" variables are not shared between instances.プラグインメジャーと非常によく似ていますが、各スクリプトメジャーはそのスクリプトの個別のインスタンスを作成します。つまり、同じスクリプトファイルからでも、スキンには任意の数のスクリプトを同時にロードできます。(スクリプトの実行順序は、メジャーの順序によって決まります。)「グローバル」変数は、インスタンス間で共有されません。
[MeasureName] |
Optionsオプション
In addition to general measure options and ScriptFile, scripts also allow user-defined options. These options may have any name and value, and may be changed with !SetOption. The script can read and use its own option values using the SELF object functions. This allows the same script file to be used with different parameters depending on the context.一般的な測定オプションとScriptFileに加えて、スクリプトはユーザー定義のオプションも許可します。これらのオプションは任意の名前と値を持つことができ、!SetOptionで変更することができます。スクリプトは、SELFオブジェクト関数を使用して独自のオプション値を読み取って使用できます。これにより、同じスクリプトファイルをコンテキストに応じて異なるパラメータで使用できます。
[MeasureName] |
Dynamic Variables動的変数
Dynamic variables are generally not needed with script measures. This is because functions are provided to get the current values of variables, measures and options within Lua. If these functions are used in the Update function, they will return the current values at the time the function is called.動的変数は通常、スクリプトメジャーでは必要ありません。これは、Lua内の変数、メジャー、およびオプションの現在の値を取得するための関数が提供されているためです。これらの関数がUpdate関数で使用されている場合、それらは関数が呼び出された時点の現在の値を返します。
!CommandMeasure!CommandMeasure
The !CommandMeasure bang can be used to execute Lua code in the context of a particular script instance:!CommandMeasure bangが特定のスクリプトインスタンスのコンテキストでLuaのコードを実行するために使用することができます。
!CommandMeasure "MyScriptMeasure" "MyFunction()"
Multiple statements may be separated by semicolons (;
). All statements are global.複数のステートメントはセミコロン(;
)で区切ることができます。すべてのステートメントはグローバルです。
!CommandMeasure "MyScriptMeasure" "a = b; print(SKIN:ParseFormula('(2+2)'))"
All statements must be passed as a single parameter in the bang. Because single-quotes ('
) and double-quotes ("
) are both valid string containers in Lua, while only double-quotes are recognized in Rainmeter, single quotes are recommended when passing strings with !CommandMeasure.すべてのステートメントは、bangの中で単一のパラメーターとして渡す必要があります。Luaでは一重引用符('
)と二重引用符("
)はどちらも有効な文字列コンテナであるため、Rainmeterでは二重引用符のみが認識されますが、!CommandMeasureで文字列を渡す場合は一重引用符をお勧めします。
Initialize初期化
If the Initialize function is defined in any script, the function is called one time (without parameters) when the skin is activated or refreshed. This happens even if the script measure is disabled. If the script file is changed by a !SetOption bang, the new script's Initialize function is called as well.場合は初期化機能は、任意のスクリプトで定義されたスキンがアクティブにされたときや、関数は(パラメータなし)1時間と呼ばれてリフレッシュ。これは、スクリプトメジャーが無効になっている場合でも発生します。!SetOption bang によってスクリプトファイルが変更された場合は、新しいスクリプトのInitialize関数も呼び出されます。
function Initialize() |
Actions that are needed to "set up" the script, such as declaring global variables, should be done in the Initialize function.グローバル変数の宣言など、スクリプトを「セットアップ」するために必要なアクションは、Initialize関数で実行する必要があります。
Using dofiledofileを使う
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 the 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.
function Initialize()
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.dofile関数は、ライブラリやLuaのコードの他の断片を含むために使用することができます。構文を使用して、dofileへのフルパスを指定する必要がありますdofile('C:\PathToDoFile\SomeLua.lua')
。使用GetVariableあなたが現在の設定のために@Resourcesフォルダに#を@#変数のショートカットを使用したい場合、または機能をMakePathAbsoluteあなたは.luaファイルが現在のスキンフォルダからの相対したい場合。
function Initialize () dofile(SKIN:GetVariable( '@').. 'MyDoFiles \\ toolkit.lua') dofile(SKIN:MakePathAbsolute( 'toolkit.lua')) end |
注:呼び出すdofileはシステム上のどこにでも置くことができますが、dofile .luaファイルを現在の構成へのパスのどこかに配置しないと、スキンとして配布することができなくなります。 .rmskinパッケージ .rmskinパッケージは、単一のルート設定フォルダーの内容のみを配布できます。
Update更新
If the Update function is defined in any script, the function is called (without parameters) whenever the script measure updates. The script measure responds normally to the Disabled option, the UpdateDivider option, and all measure bangs.場合は更新機能は、任意のスクリプトで定義され、関数がいつでもスクリプトの尺度(パラメータなし)と呼ばれるアップデート。スクリプトメジャーは、通常、Disabledオプション、UpdateDividerオプション、およびすべてのメジャーバングに応答します。
function Update() |
The Update function's return value determines what values are provided by the script measure. Strings and numbers in Lua are analogous to string values and number values in Rainmeter measures. Examples:Update関数の戻り値は、スクリプトメジャーによって提供される値を決定します。Luaの文字列と数値は、Rainmeterメジャーの文字列値と数値に似ています。例:
return
Provides 0 as the number value, and '' (blank) as the string value. The same is true if noreturn
is stated.return
提供0を数値として、そして「」文字列値として(ブランク)。noreturn
と記載されている場合も同様です。return 99
return '99'
Either way, provides 99 as the number value, and '99' as the string value.return 99
return '99'
いずれにせよ、提供99を数値として、および「99」の文字列値として。return 'Ninety-Nine'
Provides 0 as the number value (because the string cannot be converted to a number), and 'Ninety-Nine' as the string value.return 'Ninety-Nine'
提供0数値(文字列を数値に変換できないため)、およびとして「九十九」文字列値として。
The values provided by the script measure can be used in the same way as other measure values. (Note: the values only update when the measure itself updates. Calling Update()
within Lua does not update the measure values.)スクリプトメジャーによって提供される値は、他のメジャー値と同じ方法で使用できます。(注:数値は、数値データ自体が更新されたときにのみ更新されます。Lua Update()
内で呼び出しても数値データの値は更新されません。)
Logログ
Lua errors are logged in the About window. The print function may also be used to write strings to the log. This can provide helpful feedback when writing or troubleshooting a script.Luaのエラーがでログインしているについてのウィンドウ。印刷機能もログに文字列を書き込むために使用することができます。これは、スクリプトを作成またはトラブルシューティングするときに役立つフィードバックを提供します。
print('The current value of MyVariable is: ' .. MyVariable)
Functions関数
Lua functions are provided to identify a meter, a measure, or the current skin as a Lua object. Additional functions are provided for manipulating each type of object in specific ways.Lua関数は、メーター、メジャー、または現在のスキンをLua オブジェクトとして識別するために提供されています。特定の方法で各タイプのオブジェクトを操作するための追加機能が提供されています。
SKIN objectSKINオブジェクト
The SKIN
object is created automatically.SKIN
オブジェクトが自動的に作成されます。
GetMeasure
Parameter:MeasureName
GetMeasure
パラメータ:MeasureName
-
Creates a handle object for the named measure. Returns
nil
if the measure is not found.名前付きメジャーのハンドルオブジェクトを作成します。nil
小節が見つからない場合はを返します。Example:
MyMeasure = SKIN:GetMeasure('MeasureName')
例:MyMeasure = SKIN:GetMeasure('MeasureName')
GetMeter
Parameter:MeterName
GetMeter
パラメータ:MeterName
-
Creates a handle object for the named meter. Returns
nil
if the meter is not found.名前付きメーターのハンドルオブジェクトを作成します。nil
メーターが見つからない場合に返します。Example:
MyMeter = SKIN:GetMeter('MeterName')
例:MyMeter = SKIN:GetMeter('MeterName')
GetVariable
Parameter:VariableName, Default
GetVariable
パラメータ:VariableName, Default
-
Returns the current value of the named variable as a string. If the variable does not exist, returns the given default value, or
nil
if no default is given.名前付き変数の現在の値を文字列として返します。変数が存在しない場合は、指定されたデフォルト値を返すか、またはnil
デフォルトが指定されていない場合を返します。Example:
MyVariable = SKIN:GetVariable('VariableName', 'n/a')
例:MyVariable = SKIN:GetVariable('VariableName', 'n/a')
Bang
Parameters:BangName, BangArg1, BangArg2, BangArgN
Bang
パラメーター:BangName, BangArg1, BangArg2, BangArgN
-
Executes a bang. The bang will be executed by Rainmeter when control is returned from the script.強打を実行します。制御がスクリプトから返されると、bangはRainmeterによって実行されます。
Each bang parameter is a separate parameter in the function.各bangパラメータは関数内の個別のパラメータです。
Example:例:
someVar = 12
SKIN:Bang('!SetOption', 'MeterName', 'Text', 'Hello, world!')
SKIN:Bang('!SetOption', 'MeterName', 'FontSize', someVar)
SKIN:Bang('!UpdateMeter', 'MeterName')
SKIN:Bang('!Redraw')Note: The !Delay bang in Rainmeter is not supported in Lua.注意: Rainmeterの!Delay bangはLuaではサポートされていません。
MakePathAbsolute
Parameter:File/Folder
MakePathAbsolute
パラメータ:File/Folder
-
Converts a relative file path into a full file path. The path will be relative to the skin folder.相対ファイルパスをフルファイルパスに変換します。パスはスキンフォルダからの相対パスになります。
Example:
MyPath = SKIN:MakePathAbsolute('MyImage.png')
例:MyPath = SKIN:MakePathAbsolute('MyImage.png')
ReplaceVariables
Parameter:String
ReplaceVariables
パラメータ:String
-
Returns the given string, with all valid variable values properly replaced. Section variables are valid.与えられた文字列を返します。有効な変数値はすべて適切に置き換えられます。セクション変数は有効です。
Example:
MyString = SKIN:ReplaceVariables('The value of MyVariable is #MyVariable#.')
例:MyString = SKIN:ReplaceVariables('The value of MyVariable is #MyVariable#.')
ParseFormula
Parameter:FormulaString
ParseFormula
パラメータ:FormulaString
-
If the given string is a valid formula, evaluates the formula and returns the result as the number. Otherwise, returns
nil
. This can take advantage of mathematical functions in Rainmeter that may not be built into Lua. Remember that formulas in Rainmeter must be entirely enclosed in (parentheses).与えられた文字列が有効な式である場合は、式を評価して結果を数値として返します。そうでなければを返しますnil
。これは、Luaに組み込まれていないかもしれないRainmeterの数学関数を利用することができます。Rainmeterの式は完全に(括弧)で囲む必要があります。numToRound = 239.78
roundedNum = SKIN:ParseFormula('(Round('..numToRound..'))')
Measure object測定対象
A Measure
object is created using GetMeasure. It creates a handle to a specific measure in the skin, which can then be used with the following functions to act on the measure.Measure
オブジェクトが使用して作成されGetMeasureを。これは、スキン内の特定のメジャーへのハンドルを作成します。これは、次の関数と共に使用してそのメジャーに作用させることができます。
Example: MyMeasure = SKIN:GetMeasure('MeasureName')
例: MyMeasure = SKIN:GetMeasure('MeasureName')
GetValue
-
Returns the current number value of the measure.小節の現在の数値を返します。
Example:
MyMeasureValue = MyMeasure:GetValue()
例:MyMeasureValue = MyMeasure:GetValue()
GetStringValue
-
Returns the current string value of the measure.メジャーの現在の文字列値を返します。
Example:
MyMeasureValue = MyMeasure:GetStringValue()
例:MyMeasureValue = MyMeasure:GetStringValue()
GetOption
Parameters:OptionName, Default
GetOption
パラメーター:OptionName, Default
-
Returns the current value of the named option as a string. If the option does not exist, returns the given default value, or
''
if no default is given.名前付きオプションの現在の値を文字列として返します。オプションが存在しない場合は、指定されたデフォルト値を返すか、または''
デフォルトが指定されていない場合を返します。Example:
MyGroup = MyMeasure:GetOption('Group', 'None')
例:MyGroup = MyMeasure:GetOption('Group', 'None')
GetNumberOption
Parameters:OptionName, Default
GetNumberOption
パラメーター:OptionName, Default
-
Returns the current value of the named option as a number. If the option does not exist, or is not a valid number or formula, returns the given default value, or
0
if no default is given.名前付きオプションの現在の値を数値として返します。オプションが存在しない場合、または有効な数値または式では0
ない場合、指定されたデフォルト値を返すか、またはデフォルトが指定されていない場合。Example:
MyUpdateDivider = MyMeasure:GetNumberOption('UpdateDivider', 1)
例:MyUpdateDivider = MyMeasure:GetNumberOption('UpdateDivider', 1)
GetName
-
Returns the measure's name as a string.メジャーの名前を文字列として返します。
Example:
MyMeasureName = MyMeasure:GetName()
例:MyMeasureName = MyMeasure:GetName()
GetMinValue
-
Returns the current minimum value of the measure as a number.数値データとして現在の最小値を返します。
Example:
MyMeasureMin = MyMeasure:GetMinValue()
例:MyMeasureMin = MyMeasure:GetMinValue()
GetMaxValue
-
Returns the current maximum value of the measure as a number.数値データの現在の最大値を数値として返します。
Example:
MyMeasureMax = MyMeasure:GetMaxValue()
例:MyMeasureMax = MyMeasure:GetMaxValue()
GetRelativeValue
-
Returns the measure's current number percentage value as a number, scaled from
0.0
to1.0
. The result will be based on the current defined or derived MinValue and MaxValue of the measure.小節の現在のパーセント値を0.0
to でスケーリングした数値として返します1.0
。結果は、定義された電流に基づいて、または誘導されMinValueプロパティとMaxValueを尺度のを。Example:
MyMeasureValue = MyMeasure:GetRelativeValue()
例:MyMeasureValue = MyMeasure:GetRelativeValue()
GetValueRange
-
Returns the current value range of the measure as a number. The result will be based on the current defined or derived MinValue and MaxValue of the measure, and will be the difference between the two.数値データの現在の値の範囲を数値として返します。結果は、定義された電流に基づいて、または誘導されMinValueプロパティとMaxValueを数量を、両者の差であろう。
Example:
MyMeasureRange = MyMeasure:GetValueRange()
例:MyMeasureRange = MyMeasure:GetValueRange()
Disable
-
Disables the measure.測定を無効にします。
Example:
MyMeasure:Disable()
例:MyMeasure:Disable()
Enable
-
Enables the measure.測定を有効にします。
Example:
MyMeasure:Enable()
例:MyMeasure:Enable()
SELF objectSELFオブジェクト
The SELF
object is created automatically. SELF
is a measure object linked to the current script measure. All measure object functions are valid for SELF
.SELF
オブジェクトが自動的に作成されます。SELF
現在のスクリプトメジャーにリンクされているメジャーオブジェクトです。すべてのメジャーオブジェクト関数はに対して有効ですSELF
。
MyScriptMeasureName = SELF:GetName()
Meter objectメーターオブジェクト
A Meter
object is created using GetMeter. It creates a handle to a specific meter in the skin, which can then be used with the following functions to act on the meter.Meter
オブジェクトが使用して作成されGetMeterを。それはスキンの特定のメーターへのハンドルを作成します、そしてそれはそれからメーターに作用するために以下の機能で使われることができます。
Example: MyMeter = SKIN:GetMeter('MeterName')
例: MyMeter = SKIN:GetMeter('MeterName')
GetOption
Parameters:OptionName, Default
GetOption
パラメーター:OptionName, Default
-
Returns the current value of the named option as a string. If the option does not exist, returns the given default value, or
''
if no default is given.名前付きオプションの現在の値を文字列として返します。オプションが存在しない場合は、指定されたデフォルト値を返すか、または''
デフォルトが指定されていない場合を返します。Example:
MySolidColor = MyMeter:GetOption('SolidColor', '000000')
例:MySolidColor = MyMeter:GetOption('SolidColor', '000000')
GetName
-
Returns the meter's name as a string.メーターの名前を文字列として返します。
Example:
MyMeterName = MyMeter:GetName()
例:MyMeterName = MyMeter:GetName()
GetX
Parameters:Absolute
GetX
パラメーター:Absolute
-
Returns the current X position of the meter as a number. If the optional Absolute parameter is
true
, returns the absolute (or "real") X position, which may be different than the defined option on the meter.メーターの現在のX位置を数値として返します。オプションのAbsoluteパラメータがの場合、true
絶対(または"実際の")X位置を返します。これは、メーターで定義されているオプションとは異なる場合があります。Example:
MyX = MyMeter:GetX()
例:MyX = MyMeter:GetX()
GetY
Parameters:Absolute
GetY
パラメーター:Absolute
-
Returns the current Y position of the meter as a number. If the optional Absolute parameter is
true
, returns the absolute (or "real") Y position, which may be different than the defined option on the meter.メーターの現在のY位置を数値として返します。オプションのAbsoluteパラメータがの場合、true
絶対(または"実際の")Y位置を返します。これは、メーターで定義されているオプションとは異なる場合があります。Example:
MyY = MyMeter:GetY()
例:MyY = MyMeter:GetY()
GetW
-
Returns the current "real" width of the meter as a number.メーターの現在の「実際の」 幅を数値として返します。
Example:
MyW = MyMeter:GetW()
例:MyW = MyMeter:GetW()
GetH
-
Returns the current "real" height of the meter as a number.メーターの現在の「実際の」 高さを数値として返します。
Example:
MyH = MyMeter:GetH()
例:MyH = MyMeter:GetH()
SetX
-
Sets the X position of the meter.メーターのX位置を設定します。
Example:
MyMeter:SetX()
例:MyMeter:SetX()
SetY
-
Sets the Y position of the meter.メーターのY位置を設定します。
Example:
MyMeter:SetY()
例:MyMeter:SetY()
SetW
-
Sets the width of the meter.メーターの幅を設定します。
Example:
MyMeter:SetW()
例:MyMeter:SetW()
SetH
-
Sets the height of the meter.メーターの高さを設定します。
Example:
MyMeter:SetH()
例:MyMeter:SetH()
Hide
-
Example:
MyMeter:Hide()
例:MyMeter:Hide()
Show
-
Example:
MyMeter:Show()
例:MyMeter:Show()
Restrictions制限事項
The following Lua features are not available in Rainmeter at this time:現時点では、以下のLua機能はRainmeterでは使用できません。
- External compiled libraries, such as LuaCURL.LuaCURLなどの外部コンパイル済みライブラリ。
- The
require
,os.exit
,os.setlocale
,io.popen
, andcollectgarbage
functions.require
、os.exit
、os.setlocale
、io.popen
、およびcollectgarbage
機能。
Deprecated Features廃止予定の機能
The following Rainmeter-specific features have been deprecated and should not be used. They are still supported, but may be removed in future versions.以下のRainmeter固有の機能は推奨されていないため、使用しないでください。まだサポートされていますが、将来のバージョンで削除される可能性があります。
PROPERTIES = { ... }
This table was previously used to read options on the script measure. Instead, use:
SELF:GetOption('MyOption')
orSELF:GetNumberOption('MyOption')
PROPERTIES = { ... }
このテーブルは、以前はスクリプトメジャーのオプションを読み取るために使用されていました。代わりに、
SELF:GetOption('MyOption')
またはを使用してください。SELF:GetNumberOption('MyOption')
MyMeter:SetText('...')
This function was used to change a string meter's text. Instead, use:
SKIN:Bang('!SetOption', 'MeterName', 'Text', '...')
MyMeter:SetText('...')
この関数は文字列メーターのテキストを変更するために使用されました。代わりに、
SKIN:Bang('!SetOption', 'MeterName', 'Text', '...')
function GetStringValue()
This function was used to set the script measure's value. Instead, use:
function Update() ... return ... end
function GetStringValue()
この関数は、スクリプトメジャーの値を設定するために使用されていました。代わりに、
function Update() ... return ... end
関連記事
- Redirect to distributing-skins 配布スキンにリダイレクトする
- Measures 対策
- Mouse Actions マウスアクション
- Groups グループ
- Variables 変数
- Formulas 式
- Bangs 前髪
- Plugins プラグイン
- Meters メーター
- Skins スキン
- Settings 設定
- Distributing Skins (.rmskin) スキンを配布する(.rmskin)
- Arranging Skins スキンの配置
- Installing Skins スキンをインストールする
- User Interface ユーザーインターフェース
- Installing Rainmeter 雨量計の取り付け
- Getting Started 入門
- Getting Started 入門
- User Interface ユーザーインターフェース
- Distributing Skins (.rmskin) スキンを配布する(.rmskin)
- Settings 設定
- Skins スキン
- Meters メーター
- Measures 対策
- Plugins プラグイン
- Variables 変数
- Lua Scripting スクリプティングを取る
スポンサーリンク