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

From Miranda NG
Jump to navigation Jump to search
(transform to translatable version - first iteration)
(turn 'Constants' to table with linkable items)
Line 8: Line 8:
== Constants ==
== Constants ==
</translate>
</translate>
=== NULL ===
Null pointer.


{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code>
{| class="wikitable"
 
|-
=== INVALID_HANDLE_VALUE ===
!
Invalid handle.
! scope="col" | {{Ls|Content/TableHeaders/type}}
 
! scope="col" | {{Ls|Content/TableHeaders/description}}
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code>
|-
 
! scope="row" style="text-align:left" | {{Anchor|NULL}} NULL
=== CALLSERVICE_NOTFOUND ===
| style="text-align:center" | <code>light userdata</code>
Result of service call when service does not exist.
| <translate>Null pointer.</translate>
 
|-
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>number</code>
! scope="row" style="text-align:left" | {{Anchor|INVALID_HANDLE_VALUE}} INVALID_HANDLE_VALUE
| style="text-align:center" | <code>light userdata</code>
| <translate>Invalid handle.</translate>
|-
! scope="row" style="text-align:left" | {{Anchor|CALLSERVICE_NOTFOUND}} CALLSERVICE_NOTFOUND
| style="text-align:center" | <code>number</code>
| <translate>Result of service call when service does not exist.</translate>
|}


<translate>
<translate>

Revision as of 12:08, 2 June 2018

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

name
Type: 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

name
Type: string
Event name.
hook
Type: 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

hEvent
Type: 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

hEvent
Type: light userdata
Event handle received on CreateHookableEvent call.
wParam
lParam

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

name
Type: 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

name
Type: string
Service name.
wParam
lParam

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

name
Type: 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

hService
Type: light userdata
Service handle received on CreateServiceFunction call.

Example

m.DestroyServiceFunction(hService)

Other

IsPluginLoaded

Checks if plugin is loaded by its UUID.

Parameters

uuid
Type: 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.

text
Type: string

Result

     Type:: string

Example

m.Translate('Exit')

Parse

Replaces Miranda NG variables in a string.

text

Result

     Type:: string

Example

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