Plugin:MirLua/Module/m core: Difference between revisions

From Miranda NG
Jump to navigation Jump to search
(transform 'Other'; final iteration of switching to translation system)
(Marked this version for translation)
Line 1: Line 1:
<languages/>
<languages/>
<translate>
<translate>
<!--T:1-->
This module is imported into global table and available in any module through variable <tvar|var_m>'''<var>m</var>'''</>. It allows you to access basic features of Miranda NG core.
This module is imported into global table and available in any module through variable <tvar|var_m>'''<var>m</var>'''</>. It allows you to access basic features of Miranda NG core.
</translate>
</translate>
Line 7: Line 8:


<translate>
<translate>
== Constants ==
== Constants == <!--T:2-->
</translate>
</translate>


Line 18: Line 19:
! scope="row" style="text-align:left" | {{Anchor|NULL}} NULL
! scope="row" style="text-align:left" | {{Anchor|NULL}} NULL
| style="text-align:center" | <code>light userdata</code>
| style="text-align:center" | <code>light userdata</code>
| <translate>Null pointer.</translate>
| <translate><!--T:3--> Null pointer.</translate>
|-
|-
! scope="row" style="text-align:left" | {{Anchor|INVALID_HANDLE_VALUE}} INVALID_HANDLE_VALUE
! scope="row" style="text-align:left" | {{Anchor|INVALID_HANDLE_VALUE}} INVALID_HANDLE_VALUE
| style="text-align:center" | <code>light userdata</code>
| style="text-align:center" | <code>light userdata</code>
| <translate>Invalid handle.</translate>
| <translate><!--T:4--> Invalid handle.</translate>
|-
|-
! scope="row" style="text-align:left" | {{Anchor|CALLSERVICE_NOTFOUND}} CALLSERVICE_NOTFOUND
! scope="row" style="text-align:left" | {{Anchor|CALLSERVICE_NOTFOUND}} CALLSERVICE_NOTFOUND
| style="text-align:center" | <code>number</code>
| style="text-align:center" | <code>number</code>
| <translate>Result of service call when service does not exist.</translate>
| <translate><!--T:5--> Result of service call when service does not exist.</translate>
|}
|}


<translate>
<translate>
== Named events ==
== Named events == <!--T:6-->
</translate>
</translate>
=== CreateHookableEvent ===
=== CreateHookableEvent ===
<translate>Creates a hookable event.</translate>
<translate><!--T:7--> Creates a hookable event.</translate>


==== {{Ls|MirLua/Modules/parameters}} ====
==== {{Ls|MirLua/Modules/parameters}} ====
Line 46: Line 47:
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | <code>string</code>
| style="text-align:center" | <code>string</code>
| <translate>Event name.</translate>
| <translate><!--T:8--> Event name.</translate>
|}
|}


Line 52: Line 53:
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code>


{{nbsp|5}}<translate>Returns event handle if event was created successfully, otherwise <tvar|nil><code>nil</code></>.</translate>
{{nbsp|5}}<translate><!--T:9--> Returns event handle if event was created successfully, otherwise <tvar|nil><code>nil</code></>.</translate>


==== {{Ls|MirLua/Modules/example}} ====
==== {{Ls|MirLua/Modules/example}} ====
Line 64: Line 65:


=== HookEvent ===
=== HookEvent ===
<translate>Sets a callback function ("hook") to react to event call. Hooks are called one by one in the order they were added to the sequence.</translate>
<translate><!--T:10--> Sets a callback function ("hook") to react to event call. Hooks are called one by one in the order they were added to the sequence.</translate>


<translate>Hook signature: <tvar|signature><code>function (wParam, lParam) return 0 end</code></>.</translate>
<translate><!--T:11--> Hook signature: <tvar|signature><code>function (wParam, lParam) return 0 end</code></>.</translate>


<translate>Correct result for a hook is <tvar|return_0><code>0</code></>. When <tvar|return_1><code>1</code></> is returned, the following hooks in a sequence won't be called.</translate>
<translate><!--T:12--> Correct result for a hook is <tvar|return_0><code>0</code></>. When <tvar|return_1><code>1</code></> is returned, the following hooks in a sequence won't be called.</translate>


==== {{Ls|MirLua/Modules/parameters}} ====
==== {{Ls|MirLua/Modules/parameters}} ====
Line 81: Line 82:
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | <code>string</code>
| style="text-align:center" | <code>string</code>
| <translate>Event name.</translate>
| <translate><!--T:13--> Event name.</translate>
|-
|-
! scope="row" class="MirLuaParametersTable-parameter" | hook
! scope="row" class="MirLuaParametersTable-parameter" | hook
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | <code>function</code>
| style="text-align:center" | <code>function</code>
| <translate>Hook function to be called when event occurs.</translate>
| <translate><!--T:14--> Hook function to be called when event occurs.</translate>
|}
|}


Line 92: Line 93:
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code>


{{nbsp|5}}<translate>Returns hook handle if hook was created successfully, otherwise <tvar|nil><code>nil</code></>.</translate>
{{nbsp|5}}<translate><!--T:15--> Returns hook handle if hook was created successfully, otherwise <tvar|nil><code>nil</code></>.</translate>


==== {{Ls|MirLua/Modules/example}} ====
==== {{Ls|MirLua/Modules/example}} ====
Line 102: Line 103:


=== UnhookEvent ===
=== UnhookEvent ===
<translate>Removes hook from event call sequence.</translate>
<translate><!--T:16--> Removes hook from event call sequence.</translate>


==== {{Ls|MirLua/Modules/parameters}} ====
==== {{Ls|MirLua/Modules/parameters}} ====
Line 115: Line 116:
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | <code>light userdata</code>
| style="text-align:center" | <code>light userdata</code>
| <translate>Event handle received on <tvar|CreateHookableEvent>[[#CreateHookableEvent|CreateHookableEvent]]</> call.</translate>
| <translate><!--T:17--> Event handle received on <tvar|CreateHookableEvent>[[#CreateHookableEvent|CreateHookableEvent]]</> call.</translate>
|}
|}


Line 121: Line 122:
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code>


{{nbsp|5}}<translate>Returns <tvar|true><code>true</code></> if hook function was removed successfully, otherwise <tvar|false><code>false</code></>.</translate>
{{nbsp|5}}<translate><!--T:18--> Returns <tvar|true><code>true</code></> if hook function was removed successfully, otherwise <tvar|false><code>false</code></>.</translate>


==== {{Ls|MirLua/Modules/example}} ====
==== {{Ls|MirLua/Modules/example}} ====
Line 128: Line 129:


=== NotifyEventHooks ===
=== NotifyEventHooks ===
<translate>Calls all hooks of event call sequence one by one.</translate>
<translate><!--T:19--> Calls all hooks of event call sequence one by one.</translate>


==== {{Ls|MirLua/Modules/parameters}} ====
==== {{Ls|MirLua/Modules/parameters}} ====
Line 141: Line 142:
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | <code>light userdata</code>
| style="text-align:center" | <code>light userdata</code>
| <translate>Event handle received on <tvar|CreateHookableEvent>[[#CreateHookableEvent|CreateHookableEvent]]</> call.</translate>
| <translate><!--T:20--> Event handle received on <tvar|CreateHookableEvent>[[#CreateHookableEvent|CreateHookableEvent]]</> call.</translate>
|-
|-
! scope="row" class="MirLuaParametersTable-parameter" | wParam
! scope="row" class="MirLuaParametersTable-parameter" | wParam
Line 157: Line 158:
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code>


{{nbsp|5}}<translate>Returns <tvar|true><code>true</code></> if all hooks were called, otherwise <tvar|false><code>false</code></>.</translate>
{{nbsp|5}}<translate><!--T:21--> Returns <tvar|true><code>true</code></> if all hooks were called, otherwise <tvar|false><code>false</code></>.</translate>


==== {{Ls|MirLua/Modules/example}} ====
==== {{Ls|MirLua/Modules/example}} ====
Line 163: Line 164:


<translate>
<translate>
== Named service functions ==
== Named service functions == <!--T:22-->
</translate>
</translate>
=== CreateServiceFunction ===
=== CreateServiceFunction ===
<translate>Creates a service function ("service").</translate>
<translate><!--T:23--> Creates a service function ("service").</translate>


==== {{Ls|MirLua/Modules/parameters}} ====
==== {{Ls|MirLua/Modules/parameters}} ====
Line 179: Line 180:
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | <code>string</code>
| style="text-align:center" | <code>string</code>
| <translate>Service name.</translate>
| <translate><!--T:24--> Service name.</translate>
|}
|}


Line 185: Line 186:
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code>


{{nbsp|5}}<translate>Returns service handle if service was created successfully, otherwise <tvar|nil><code>nil</code></>.</translate>
{{nbsp|5}}<translate><!--T:25--> Returns service handle if service was created successfully, otherwise <tvar|nil><code>nil</code></>.</translate>


==== {{Ls|MirLua/Modules/example}} ====
==== {{Ls|MirLua/Modules/example}} ====
Line 195: Line 196:


=== CallService ===
=== CallService ===
<translate>Calls service with parameters.</translate>
<translate><!--T:26--> Calls service with parameters.</translate>


==== {{Ls|MirLua/Modules/parameters}} ====
==== {{Ls|MirLua/Modules/parameters}} ====
Line 208: Line 209:
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | <code>string</code>
| style="text-align:center" | <code>string</code>
| <translate>Service name.</translate>
| <translate><!--T:27--> Service name.</translate>
|-
|-
! scope="row" class="MirLuaParametersTable-parameter" | wParam
! scope="row" class="MirLuaParametersTable-parameter" | wParam
Line 224: Line 225:
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>number</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>number</code>


{{nbsp|5}}<translate>Returns result of service execution or <tvar|CALLSERVICE_NOTFOUND>[[#CALLSERVICE_NOTFOUND|CALLSERVICE_NOTFOUND]]</>.</translate>
{{nbsp|5}}<translate><!--T:28--> Returns result of service execution or <tvar|CALLSERVICE_NOTFOUND>[[#CALLSERVICE_NOTFOUND|CALLSERVICE_NOTFOUND]]</>.</translate>


==== {{Ls|MirLua/Modules/example}} ====
==== {{Ls|MirLua/Modules/example}} ====
Line 236: Line 237:


=== ServiceExists ===
=== ServiceExists ===
<translate>Checks if service exists by its name.</translate>
<translate><!--T:29--> Checks if service exists by its name.</translate>


==== {{Ls|MirLua/Modules/parameters}} ====
==== {{Ls|MirLua/Modules/parameters}} ====
Line 249: Line 250:
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | <code>string</code>
| style="text-align:center" | <code>string</code>
| <translate>Service name.</translate>
| <translate><!--T:30--> Service name.</translate>
|}
|}


Line 255: Line 256:
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code>


{{nbsp|5}}<translate>Returns <tvar|true><code>true</code></> if service exists, otherwise <tvar|false><code>false</code></>.</translate>
{{nbsp|5}}<translate><!--T:31--> Returns <tvar|true><code>true</code></> if service exists, otherwise <tvar|false><code>false</code></>.</translate>


==== {{Ls|MirLua/Modules/example}} ====
==== {{Ls|MirLua/Modules/example}} ====
Line 264: Line 265:


=== DestroyServiceFunction ===
=== DestroyServiceFunction ===
<translate>Destroys a service function.</translate>
<translate><!--T:32--> Destroys a service function.</translate>


==== {{Ls|MirLua/Modules/parameters}} ====
==== {{Ls|MirLua/Modules/parameters}} ====
Line 277: Line 278:
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | <code>light userdata</code>
| style="text-align:center" | <code>light userdata</code>
| <translate>Service handle received on <tvar|CreateServiceFunction>[[#CreateServiceFunction|CreateServiceFunction]]</> call.</translate>
| <translate><!--T:33--> Service handle received on <tvar|CreateServiceFunction>[[#CreateServiceFunction|CreateServiceFunction]]</> call.</translate>
|}
|}


Line 284: Line 285:


<translate>
<translate>
== Other ==
== Other == <!--T:34-->
</translate>
</translate>
=== IsPluginLoaded ===
=== IsPluginLoaded ===
<translate>Checks using UUID of the plugin whether it is loaded.</translate>
<translate><!--T:35--> Checks using UUID of the plugin whether it is loaded.</translate>


==== {{Ls|MirLua/Modules/parameters}} ====
==== {{Ls|MirLua/Modules/parameters}} ====
Line 300: Line 301:
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | <code>string</code>
| style="text-align:center" | <code>string</code>
| <translate>Plugin UUID in format <tvar|uuid_format>''<code>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</code>''</>.</translate>
| <translate><!--T:36--> Plugin UUID in format <tvar|uuid_format>''<code>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</code>''</>.</translate>
|}
|}


Line 306: Line 307:
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code>


{{nbsp|5}}<translate>Returns <tvar|true><code>true</code></> if plugin is loaded, otherwise <tvar|false><code>false</code></>.</translate>
{{nbsp|5}}<translate><!--T:37--> Returns <tvar|true><code>true</code></> if plugin is loaded, otherwise <tvar|false><code>false</code></>.</translate>


==== {{Ls|MirLua/Modules/example}} ====
==== {{Ls|MirLua/Modules/example}} ====
Line 316: Line 317:


=== Translate ===
=== Translate ===
<translate>Translates a string into the language of the current langpack.</translate>
<translate><!--T:38--> Translates a string into the language of the current langpack.</translate>


==== {{Ls|MirLua/Modules/parameters}} ====
==== {{Ls|MirLua/Modules/parameters}} ====
Line 340: Line 341:


=== Parse ===
=== Parse ===
<translate>Replaces Miranda NG variables in a string.</translate>
<translate><!--T:39--> Replaces Miranda NG variables in a string.</translate>


{| class="wikitable"
{| class="wikitable"

Revision as of 13:25, 2 June 2018

Other languages:

This module is imported into global table and available in any module through variable m. It allows you to access basic features of Miranda NG core.

Constants

Type Description
NULL light userdata Null pointer.
INVALID_HANDLE_VALUE light userdata Invalid handle.
CALLSERVICE_NOTFOUND number Result of service call when service does not exist.

Named events

CreateHookableEvent

Creates a hookable event.

Parameters

Parameter name Required Type Description
name Yes string Event name.

Result

     Type:: light userdata

     Returns event handle if event was created successfully, otherwise nil.

Example

local hEvent = m.CreateHookableEvent('MyEvent')
if hEvent == m.NULL then
  print('Event handle is empty!')
end

HookEvent

Sets a callback function ("hook") to react to event call. Hooks are called one by one in the order they were added to the sequence.

Hook signature: function (wParam, lParam) return 0 end.

Correct result for a hook is 0. When 1 is returned, the following hooks in a sequence won't be called.

Parameters

Parameter name Required Type Description
name Yes string Event name.
hook Yes function Hook function to be called when event occurs.

Result

     Type:: light userdata

     Returns hook handle if hook was created successfully, otherwise nil.

Example

local hHook = m.HookEvent('MyEvent', function(w, l)
  print('MyEvent is raised!')
end)

UnhookEvent

Removes hook from event call sequence.

Parameters

Parameter name Required Type Description
hEvent Yes light userdata Event handle received on CreateHookableEvent call.

Result

     Type:: boolean

     Returns true if hook function was removed successfully, otherwise false.

Example

m.UnhookEvent(hHook)

NotifyEventHooks

Calls all hooks of event call sequence one by one.

Parameters

Parameter name Required Type Description
hEvent Yes light userdata Event handle received on CreateHookableEvent call.
wParam No
lParam No

Result

     Type:: boolean

     Returns true if all hooks were called, otherwise false.

Example

m.NotifyEventHooks(hEvent)

Named service functions

CreateServiceFunction

Creates a service function ("service").

Parameters

Parameter name Required Type Description
name Yes string Service name.

Result

     Type:: light userdata

     Returns service handle if service was created successfully, otherwise nil.

Example

local hService = m.CreateServiceFunction('MyService', function(w, l)
  print('MyServiceis called!')
end)

CallService

Calls service with parameters.

Parameters

Parameter name Required Type Description
name Yes string Service name.
wParam No
lParam No

Result

     Type:: number

     Returns result of service execution or CALLSERVICE_NOTFOUND.

Example

local result = m.CallService('MyService')
if result == m.CALLSERVICE_NOTFOUND then
  print('Service is not found!')
end

ServiceExists

Checks if service exists by its name.

Parameters

Parameter name Required Type Description
name Yes string Service name.

Result

     Type:: boolean

     Returns true if service exists, otherwise false.

Example

if m.ServiceExists('MyService') then
  m.CallService('MyService')
end

DestroyServiceFunction

Destroys a service function.

Parameters

Parameter name Required Type Description
hService Yes light userdata Service handle received on CreateServiceFunction call.

Example

m.DestroyServiceFunction(hService)

Other

IsPluginLoaded

Checks using UUID of the plugin whether it is loaded.

Parameters

Parameter name Required Type Description
uuid Yes string Plugin UUID in format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

Result

     Type:: boolean

     Returns true if plugin is loaded, otherwise false.

Example

if m.IsPluginLoaded('{F0FDF73A-753D-499d-8DBA-336DB79CDD41}') then
  print('Advanced auto away plugin is loaded!')
end

Translate

Translates a string into the language of the current langpack.

Parameters

Parameter name Required Type Description
text Yes string

Result

     Type:: string

Example

m.Translate('Exit')

Parse

Replaces Miranda NG variables in a string.

Parameter name Required Type Description
text Yes string

Result

     Type:: string

Example

local profileName = m.ReplaceVariables('%miranda_profilename%')