Plugin:MirLua/Module/m core/ru

From Miranda NG
< Plugin:MirLua
Revision as of 13:26, 2 June 2018 by FuzzyBot (talk | contribs) (Updating to match new version of source page)
Jump to navigation Jump to search
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

Тип Описание
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.

Параметры

Имя параметра Required Тип Описание
name Да string Event name.

Результат

     Тип:: light userdata

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

Пример

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.

Параметры

Имя параметра Required Тип Описание
name Да string Event name.
hook Да function Hook function to be called when event occurs.

Результат

     Тип:: light userdata

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

Пример

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

UnhookEvent

Removes hook from event call sequence.

Параметры

Имя параметра Required Тип Описание
hEvent Да light userdata Event handle received on CreateHookableEvent call.

Результат

     Тип:: boolean

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

Пример

m.UnhookEvent(hHook)

NotifyEventHooks

Calls all hooks of event call sequence one by one.

Параметры

Имя параметра Required Тип Описание
hEvent Да light userdata Event handle received on CreateHookableEvent call.
wParam Нет
lParam Нет

Результат

     Тип:: boolean

     Returns true if all hooks were called, otherwise false.

Пример

m.NotifyEventHooks(hEvent)

Named service functions

CreateServiceFunction

Creates a service function ("service").

Параметры

Имя параметра Required Тип Описание
name Да string Service name.

Результат

     Тип:: light userdata

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

Пример

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

CallService

Calls service with parameters.

Параметры

Имя параметра Required Тип Описание
name Да string Service name.
wParam Нет
lParam Нет

Результат

     Тип:: number

     Returns result of service execution or CALLSERVICE_NOTFOUND.

Пример

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.

Параметры

Имя параметра Required Тип Описание
name Да string Service name.

Результат

     Тип:: boolean

     Returns true if service exists, otherwise false.

Пример

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

DestroyServiceFunction

Destroys a service function.

Параметры

Имя параметра Required Тип Описание
hService Да light userdata Service handle received on CreateServiceFunction call.

Пример

m.DestroyServiceFunction(hService)

Other

IsPluginLoaded

Checks using UUID of the plugin whether it is loaded.

Параметры

Имя параметра Required Тип Описание
uuid Да string Plugin UUID in format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

Результат

     Тип:: boolean

     Returns true if plugin is loaded, otherwise false.

Пример

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.

Параметры

Имя параметра Required Тип Описание
text Да string

Результат

     Тип:: string

Пример

m.Translate('Exit')

Parse

Replaces Miranda NG variables in a string.

Имя параметра Required Тип Описание
text Да string

Результат

     Тип:: string

Пример

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