Plugin:MirLua/Module/m core: Difference between revisions
m (Goraf moved page Plugin:MirLua/Module/m core to Plugin:MirLua/Module/m core: to transform to translation system) |
(transform to translatable version - first iteration) |
||
Line 1: | Line 1: | ||
<translate> | |||
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. | 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> | |||
__TOC__ | __TOC__ | ||
<translate> | |||
== Constants == | == Constants == | ||
</translate> | |||
=== NULL === | === NULL === | ||
Null pointer. | Null pointer. | ||
: | |||
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code> | |||
=== INVALID_HANDLE_VALUE === | === INVALID_HANDLE_VALUE === | ||
Invalid handle. | Invalid handle. | ||
: | |||
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code> | |||
=== CALLSERVICE_NOTFOUND === | === CALLSERVICE_NOTFOUND === | ||
Result of service call when service does not exist. | Result of service call when service does not exist. | ||
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>number</code> | |||
<translate> | |||
== Named events == | == Named events == | ||
</translate> | |||
=== CreateHookableEvent === | === CreateHookableEvent === | ||
Creates a hookable event. | Creates a hookable event. | ||
==== {{Ls|MirLua/Modules/parameters}} ==== | |||
: '''''name''''' | : '''''name''''' | ||
:: Type: | :: Type: <code>string</code> | ||
:: Event name. | :: Event name. | ||
: | ==== {{Ls|MirLua/Modules/result}} ==== | ||
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code> | |||
: Returns event handle if event was created successfully, otherwise '''nil'''. | : Returns event handle if event was created successfully, otherwise '''nil'''. | ||
==== {{Ls|MirLua/Modules/example}} ==== | |||
{{Content:MirLua/Example|code= | |||
local hEvent = m.CreateHookableEvent('MyEvent') | local hEvent = m.CreateHookableEvent('MyEvent') | ||
if hEvent == m.NULL then | if hEvent == m.NULL then | ||
print('Event handle is empty!') | print('Event handle is empty!') | ||
end | end | ||
}} | |||
---- | |||
=== HookEvent === | === HookEvent === | ||
Line 45: | Line 53: | ||
Correct result for a hook is 0. When 1 is returned, the following hooks in a sequence won't be called. | Correct result for a hook is 0. When 1 is returned, the following hooks in a sequence won't be called. | ||
==== {{Ls|MirLua/Modules/parameters}} ==== | |||
: '''''name''''' | : '''''name''''' | ||
:: Type: | :: Type: <code>string</code> | ||
:: Event name. | :: Event name. | ||
: '''''hook''''' | : '''''hook''''' | ||
:: Type: | :: Type: <code>function</code> | ||
:: Hook function to be called when event occurs. | :: Hook function to be called when event occurs. | ||
: | ==== {{Ls|MirLua/Modules/result}} ==== | ||
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code> | |||
: Returns hook handle if hook was created successfully, otherwise '''nil'''. | : Returns hook handle if hook was created successfully, otherwise '''nil'''. | ||
==== {{Ls|MirLua/Modules/example}} ==== | |||
{{Content:MirLua/Example|code=local hHook = m.HookEvent('MyEvent', function(w, l) | {{Content:MirLua/Example|code=local hHook = m.HookEvent('MyEvent', function(w, l) | ||
print('MyEvent is raised!') | print('MyEvent is raised!') | ||
end) | end) | ||
}} | }} | ||
---- | |||
=== UnhookEvent === | === UnhookEvent === | ||
Removes hook from event call sequence. | Removes hook from event call sequence. | ||
==== {{Ls|MirLua/Modules/parameters}} ==== | |||
: '''''hEvent''''' | : '''''hEvent''''' | ||
:: Type: | :: Type: <code>light userdata</code> | ||
:: Event handle received on [[#CreateHookableEvent|CreateHookableEvent]] call. | :: Event handle received on [[#CreateHookableEvent|CreateHookableEvent]] call. | ||
: | ==== {{Ls|MirLua/Modules/result}} ==== | ||
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code> | |||
: Returns '''true''' if hook function was removed successfully, otherwise '''false'''. | : Returns '''true''' if hook function was removed successfully, otherwise '''false'''. | ||
==== {{Ls|MirLua/Modules/example}} ==== | |||
{{Content:MirLua/Example|code=m.UnhookEvent(hHook)}} | {{Content:MirLua/Example|code=m.UnhookEvent(hHook)}} | ||
---- | |||
=== NotifyEventHooks === | === NotifyEventHooks === | ||
Calls all hooks of event call sequence one by one. | Calls all hooks of event call sequence one by one. | ||
==== {{Ls|MirLua/Modules/parameters}} ==== | |||
: '''''hEvent''''' | : '''''hEvent''''' | ||
:: Type: | :: Type: <code>light userdata</code> | ||
:: Event handle received on [[#CreateHookableEvent|CreateHookableEvent]] call. | :: Event handle received on [[#CreateHookableEvent|CreateHookableEvent]] call. | ||
: ''wParam'' | : ''wParam'' | ||
: ''lParam'' | : ''lParam'' | ||
: | ==== {{Ls|MirLua/Modules/result}} ==== | ||
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code> | |||
: Returns '''true''' if all hooks were called, otherwise '''false'''. | : Returns '''true''' if all hooks were called, otherwise '''false'''. | ||
==== {{Ls|MirLua/Modules/example}} ==== | |||
{{Content:MirLua/Example|code=m.NotifyEventHooks(hEvent)}} | {{Content:MirLua/Example|code=m.NotifyEventHooks(hEvent)}} | ||
<translate> | |||
== Named service functions == | == Named service functions == | ||
</translate> | |||
=== CreateServiceFunction === | === CreateServiceFunction === | ||
Creates a service function ("service") | Creates a service function ("service") | ||
==== {{Ls|MirLua/Modules/parameters}} ==== | |||
: '''''name''''' | : '''''name''''' | ||
:: Type: | :: Type: <code>string</code> | ||
:: Service name. | :: Service name. | ||
: | ==== {{Ls|MirLua/Modules/result}} ==== | ||
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code> | |||
: Returns service handle if service was created successfully, otherwise '''nil'''. | : Returns service handle if service was created successfully, otherwise '''nil'''. | ||
==== {{Ls|MirLua/Modules/example}} ==== | |||
{{Content:MirLua/Example|code=local hService = m.CreateServiceFunction('MyService', function(w, l) | {{Content:MirLua/Example|code=local hService = m.CreateServiceFunction('MyService', function(w, l) | ||
print('MyServiceis called!') | print('MyServiceis called!') | ||
end) | end) | ||
}} | }} | ||
---- | |||
=== CallService === | === CallService === | ||
Calls service with parameters. | Calls service with parameters. | ||
==== {{Ls|MirLua/Modules/parameters}} ==== | |||
: '''''name''''' | : '''''name''''' | ||
:: Type: | :: Type: <code>string</code> | ||
:: Service name. | :: Service name. | ||
: ''wParam'' | : ''wParam'' | ||
: ''lParam'' | : ''lParam'' | ||
: | ==== {{Ls|MirLua/Modules/result}} ==== | ||
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>number</code> | |||
: Returns result of service execution or [[#CALLSERVICE_NOTFOUND|CALLSERVICE_NOTFOUND]] | : Returns result of service execution or [[#CALLSERVICE_NOTFOUND|CALLSERVICE_NOTFOUND]] | ||
==== {{Ls|MirLua/Modules/example}} ==== | |||
{{Content:MirLua/Example|code= | {{Content:MirLua/Example|code= | ||
local result = m.CallService('MyService') | local result = m.CallService('MyService') | ||
Line 122: | Line 149: | ||
end | end | ||
}} | }} | ||
---- | |||
=== ServiceExists === | === ServiceExists === | ||
Checks if service exists by its name. | Checks if service exists by its name. | ||
==== {{Ls|MirLua/Modules/parameters}} ==== | |||
: '''''name''''' | : '''''name''''' | ||
:: Type: | :: Type: <code>string</code> | ||
:: Service name. | :: Service name. | ||
: | ==== {{Ls|MirLua/Modules/result}} ==== | ||
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code> | |||
: Returns '''true''' if service exists, otherwise '''false''' | : Returns '''true''' if service exists, otherwise '''false''' | ||
==== {{Ls|MirLua/Modules/example}} ==== | |||
{{Content:MirLua/Example|code=if m.ServiceExists('MyService') then | {{Content:MirLua/Example|code=if m.ServiceExists('MyService') then | ||
m.CallService('MyService') | m.CallService('MyService') | ||
end}} | end}} | ||
---- | |||
=== DestroyServiceFunction === | === DestroyServiceFunction === | ||
Destroys a service function. | Destroys a service function. | ||
==== {{Ls|MirLua/Modules/parameters}} ==== | |||
: '''''hService''''' | : '''''hService''''' | ||
:: Type: | :: Type: <code>light userdata</code> | ||
:: Service handle received on [[#CreateServiceFunction|CreateServiceFunction]] call. | :: Service handle received on [[#CreateServiceFunction|CreateServiceFunction]] call. | ||
==== {{Ls|MirLua/Modules/example}} ==== | |||
{{Content:MirLua/Example|code=m.DestroyServiceFunction(hService)}} | {{Content:MirLua/Example|code=m.DestroyServiceFunction(hService)}} | ||
<translate> | |||
== | == Other == | ||
</translate> | |||
=== IsPluginLoaded === | === IsPluginLoaded === | ||
Checks if plugin is loaded by its UUID. | Checks if plugin is loaded by its UUID. | ||
==== {{Ls|MirLua/Modules/parameters}} ==== | |||
: '''''uuid''''' | : '''''uuid''''' | ||
:: Type: | :: Type: <code>string</code> | ||
:: Plugin UUID in format ''xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx''. | :: Plugin UUID in format ''xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx''. | ||
: | ==== {{Ls|MirLua/Modules/result}} ==== | ||
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>boolean</code> | |||
: Returns '''true''' if plugin is loaded, otherwise '''false'''. | : Returns '''true''' if plugin is loaded, otherwise '''false'''. | ||
==== {{Ls|MirLua/Modules/example}} ==== | |||
{{Content:MirLua/Example|code=if m.IsPluginLoaded('{F0FDF73A-753D-499d-8DBA-336DB79CDD41}') then | {{Content:MirLua/Example|code=if m.IsPluginLoaded('{F0FDF73A-753D-499d-8DBA-336DB79CDD41}') then | ||
print('Advanced auto away plugin is loaded!') | print('Advanced auto away plugin is loaded!') | ||
end | end | ||
}} | }} | ||
---- | |||
=== Translate === | === Translate === | ||
Translates a string into the language of the current langpack. | Translates a string into the language of the current langpack. | ||
: '''''text''''' | : '''''text''''' | ||
:: Type: | :: Type: <code>string</code> | ||
: | ==== {{Ls|MirLua/Modules/result}} ==== | ||
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>string</code> | |||
==== {{Ls|MirLua/Modules/example}} ==== | |||
{{Content:MirLua/Example|code=m.Translate('Exit')}} | {{Content:MirLua/Example|code=m.Translate('Exit')}} | ||
---- | |||
=== Parse === | === Parse === | ||
Replaces Miranda NG variables in a string. | Replaces Miranda NG variables in a string. | ||
: '''''text''''' | : '''''text''''' | ||
: | ==== {{Ls|MirLua/Modules/result}} ==== | ||
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>string</code> | |||
==== {{Ls|MirLua/Modules/example}} ==== | |||
{{Content:MirLua/Example|code=local profileName = m.ReplaceVariables('%miranda_profilename%')}} | {{Content:MirLua/Example|code=local profileName = m.ReplaceVariables('%miranda_profilename%')}} | ||
Revision as of 10:38, 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
NULL
Null pointer.
Type:: light userdata
INVALID_HANDLE_VALUE
Invalid handle.
Type:: light userdata
CALLSERVICE_NOTFOUND
Result of service call when service does not exist.
Type:: number
Named events
CreateHookableEvent
Creates a hookable event.
Parameters
- name
- Type:
string
- Event name.
- Type:
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.
- Type:
- hook
- Type:
function
- Hook function to be called when event occurs.
- Type:
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.
- Type:
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.
- Type:
- 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.
- Type:
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.
- Type:
- 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.
- Type:
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.
- Type:
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.
- Type:
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
- Type:
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%')