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

From Miranda NG
Jump to navigation Jump to search
(Updating to match new version of source page)
 
(Updating to match new version of source page)
 
(One intermediate revision by the same user not shown)
Line 23: Line 23:
| style="text-align:center" | <code>number</code>
| style="text-align:center" | <code>number</code>
| Result of service call when service does not exist.
| Result of service call when service does not exist.
|-
! scope="row" style="text-align:left" | Version
| style="text-align:center" | <code>string</code>
|
|}
|}


== Named events ==
== Named events ==
=== CreateHookableEvent ===
=== CreateHookableEvent ===
Creates a hookable event.
Creates a hookable event.
Line 44: Line 49:


==== {{Ls|MirLua/Modules/result}} ====
==== {{Ls|MirLua/Modules/result}} ====
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}} <code>light userdata</code>


{{nbsp|5}}Returns event handle if event was created successfully, otherwise <code>nil</code>.
{{nbsp|5}}Returns event handle if event was created successfully, otherwise <code>nil</code>.
Line 84: Line 89:


==== {{Ls|MirLua/Modules/result}} ====
==== {{Ls|MirLua/Modules/result}} ====
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}} <code>light userdata</code>


{{nbsp|5}}Returns hook handle if hook was created successfully, otherwise <code>nil</code>.
{{nbsp|5}}Returns hook handle if hook was created successfully, otherwise <code>nil</code>.
Line 93: Line 98:
end)
end)
}}
}}
----
=== HookTemporaryEvent ===
==== {{Ls|MirLua/Modules/parameters}} ====
{| class="wikitable"
|-
! scope="col" | {{Ls|MirLua/Modules/param_name}}
! scope="col" | {{Ls|MirLua/Modules/required_param}}
! scope="col" | {{Ls|Content/TableHeaders/type}}
! scope="col" | {{Ls|Content/TableHeaders/description}}
|-
! scope="row" class="MirLuaParametersTable-parameter" | name
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | <code>string</code>
| Event name.
|-
! scope="row" class="MirLuaParametersTable-parameter" | hook
| style="text-align:center" | {{Ls|YesNo/yes}}
| style="text-align:center" | <code>function</code>
| Hook function to be called when event occurs.
|}
==== {{Ls|MirLua/Modules/result}} ====
==== {{Ls|MirLua/Modules/example}} ====
----
----


Line 113: Line 147:


==== {{Ls|MirLua/Modules/result}} ====
==== {{Ls|MirLua/Modules/result}} ====
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}} <code>boolean</code>


{{nbsp|5}}Returns <code>true</code> if hook function was removed successfully, otherwise <code>false</code>.
{{nbsp|5}}Returns <code>true</code> if hook function was removed successfully, otherwise <code>false</code>.
Line 149: Line 183:


==== {{Ls|MirLua/Modules/result}} ====
==== {{Ls|MirLua/Modules/result}} ====
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}} <code>boolean</code>


{{nbsp|5}}Returns <code>true</code> if all hooks were called, otherwise <code>false</code>.
{{nbsp|5}}Returns <code>true</code> if all hooks were called, otherwise <code>false</code>.
Line 157: Line 191:


== Named service functions ==
== Named service functions ==
=== CreateServiceFunction ===
=== CreateServiceFunction ===
Creates a service function ("service").
Creates a service function ("service").
Line 175: Line 210:


==== {{Ls|MirLua/Modules/result}} ====
==== {{Ls|MirLua/Modules/result}} ====
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}} <code>light userdata</code>


{{nbsp|5}}Returns service handle if service was created successfully, otherwise <code>nil</code>.
{{nbsp|5}}Returns service handle if service was created successfully, otherwise <code>nil</code>.
Line 214: Line 249:


==== {{Ls|MirLua/Modules/result}} ====
==== {{Ls|MirLua/Modules/result}} ====
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>number</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}} <code>number</code>


{{nbsp|5}}Returns result of service execution or [[#CALLSERVICE_NOTFOUND|CALLSERVICE_NOTFOUND]].
{{nbsp|5}}Returns result of service execution or [[#CALLSERVICE_NOTFOUND|CALLSERVICE_NOTFOUND]].
Line 245: Line 280:


==== {{Ls|MirLua/Modules/result}} ====
==== {{Ls|MirLua/Modules/result}} ====
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}} <code>boolean</code>


{{nbsp|5}}Returns <code>true</code> if service exists, otherwise <code>false</code>.
{{nbsp|5}}Returns <code>true</code> if service exists, otherwise <code>false</code>.
Line 274: Line 309:
==== {{Ls|MirLua/Modules/example}} ====
==== {{Ls|MirLua/Modules/example}} ====
{{Content:MirLua/Example|code=m.DestroyServiceFunction(hService)}}
{{Content:MirLua/Example|code=m.DestroyServiceFunction(hService)}}
== Threads ==
=== ForkThread ===
----
=== TerminateThread ===


== Other ==
== Other ==
=== IsPluginLoaded ===
=== IsPluginLoaded ===
Checks using UUID of the plugin whether it is loaded.
Checks using UUID of the plugin whether it is loaded.
Line 294: Line 339:


==== {{Ls|MirLua/Modules/result}} ====
==== {{Ls|MirLua/Modules/result}} ====
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}} <code>boolean</code>


{{nbsp|5}}Returns <code>true</code> if plugin is loaded, otherwise <code>false</code>.
{{nbsp|5}}Returns <code>true</code> if plugin is loaded, otherwise <code>false</code>.
Line 303: Line 348:
end
end
}}
}}
----
=== Free ===
----
----


Line 323: Line 372:


==== {{Ls|MirLua/Modules/result}} ====
==== {{Ls|MirLua/Modules/result}} ====
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>string</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}} <code>string</code>


==== {{Ls|MirLua/Modules/example}} ====
==== {{Ls|MirLua/Modules/example}} ====
Line 346: Line 395:


==== {{Ls|MirLua/Modules/result}} ====
==== {{Ls|MirLua/Modules/result}} ====
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>string</code>
{{nbsp|5}}{{Ls|MirLua/Modules/type}} <code>string</code>


==== {{Ls|MirLua/Modules/example}} ====
==== {{Ls|MirLua/Modules/example}} ====
{{Content:MirLua/Example|code=local profileName = m.ReplaceVariables('%miranda_profilename%')}}
{{Content:MirLua/Example|code=local profileName = m.ReplaceVariables('%miranda_profilename%')}}
----
=== GetFullPath ===

Latest revision as of 02:02, 10 February 2022

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.
Version string

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)

HookTemporaryEvent

Parameters

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

Result

Example


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)

Threads

ForkThread


TerminateThread

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

Free


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%')

GetFullPath