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

From Miranda NG
Jump to navigation Jump to search
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:
{{PageLang|en}}
<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>
{{Note|Parameters written in '''''bold italics''''' are obligatory.}}
 


__TOC__
__TOC__


<translate>
== Constants ==
== Constants ==
</translate>
=== NULL ===
=== NULL ===
Null pointer.
Null pointer.
: Type: '''light userdata'''
 
{{nbsp|5}}{{Ls|MirLua/Modules/type}}: <code>light userdata</code>


=== INVALID_HANDLE_VALUE ===
=== INVALID_HANDLE_VALUE ===
Invalid handle.
Invalid handle.
: Type: '''light userdata'''
 
{{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.
: Type: '''number'''


{{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.
;Parameters
 
==== {{Ls|MirLua/Modules/parameters}} ====
: '''''name'''''
: '''''name'''''
:: Type: '''string'''
:: Type: <code>string</code>
:: Event name.
:: Event name.
;Result
 
: Type: '''light userdata'''
==== {{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'''.
;Example
 
<pre style="overflow:auto;">
==== {{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
</pre>
}}
----


=== 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.
;Parameters
 
==== {{Ls|MirLua/Modules/parameters}} ====
: '''''name'''''
: '''''name'''''
:: Type: '''string'''
:: Type: <code>string</code>
:: Event name.
:: Event name.
: '''''hook'''''
: '''''hook'''''
:: Type: '''function'''
:: Type: <code>function</code>
:: Hook function to be called when event occurs.
:: Hook function to be called when event occurs.
;Result
 
: Type: '''light userdata'''
==== {{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'''.
;Example
 
==== {{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.
;Parameters
 
==== {{Ls|MirLua/Modules/parameters}} ====
: '''''hEvent'''''
: '''''hEvent'''''
:: Type: '''light userdata'''
:: Type: <code>light userdata</code>
:: Event handle received on [[#CreateHookableEvent|CreateHookableEvent]] call.
:: Event handle received on [[#CreateHookableEvent|CreateHookableEvent]] call.
;Result
 
: Type: '''boolean'''
==== {{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'''.
;Example
 
==== {{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.
;Parameters
 
==== {{Ls|MirLua/Modules/parameters}} ====
: '''''hEvent'''''
: '''''hEvent'''''
:: Type: '''light userdata'''
:: Type: <code>light userdata</code>
:: Event handle received on [[#CreateHookableEvent|CreateHookableEvent]] call.
:: Event handle received on [[#CreateHookableEvent|CreateHookableEvent]] call.
: ''wParam''
: ''wParam''
: ''lParam''
: ''lParam''
;Result
 
: Type: '''boolean'''
==== {{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'''.
;Example
 
==== {{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")
;Parameters
 
==== {{Ls|MirLua/Modules/parameters}} ====
: '''''name'''''
: '''''name'''''
:: Type: '''string'''
:: Type: <code>string</code>
:: Service name.
:: Service name.
;Result
 
: Type: '''light userdata'''
==== {{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'''.
;Example
 
==== {{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.
;Parameters
 
==== {{Ls|MirLua/Modules/parameters}} ====
: '''''name'''''
: '''''name'''''
:: Type: '''string'''
:: Type: <code>string</code>
:: Service name.
:: Service name.
: ''wParam''
: ''wParam''
: ''lParam''
: ''lParam''
;Result
 
: Type: '''number'''
==== {{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]]
;Example
 
==== {{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.
;Parameters
 
==== {{Ls|MirLua/Modules/parameters}} ====
: '''''name'''''
: '''''name'''''
:: Type: '''string'''
:: Type: <code>string</code>
:: Service name.
:: Service name.
;Result
 
: Type: '''boolean'''
==== {{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'''
;Example
 
==== {{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.
;Parameters
 
==== {{Ls|MirLua/Modules/parameters}} ====
: '''''hService'''''
: '''''hService'''''
:: Type: '''light userdata'''
:: Type: <code>light userdata</code>
:: Service handle received on [[#CreateServiceFunction|CreateServiceFunction]] call.
:: Service handle received on [[#CreateServiceFunction|CreateServiceFunction]] call.
;Example
 
==== {{Ls|MirLua/Modules/example}} ====
{{Content:MirLua/Example|code=m.DestroyServiceFunction(hService)}}
{{Content:MirLua/Example|code=m.DestroyServiceFunction(hService)}}


 
<translate>
== Others ==
== Other ==
</translate>
=== IsPluginLoaded ===
=== IsPluginLoaded ===
Checks if plugin is loaded by its UUID.
Checks if plugin is loaded by its UUID.
;Parameters
 
==== {{Ls|MirLua/Modules/parameters}} ====
: '''''uuid'''''
: '''''uuid'''''
:: Type: '''string'''
:: Type: <code>string</code>
:: Plugin UUID in format ''xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx''.
:: Plugin UUID in format ''xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx''.
;Result
 
: Type: '''boolean'''
==== {{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'''.
;Example
 
==== {{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: '''string'''
:: Type: <code>string</code>
;Result
 
: Type: '''string'''
==== {{Ls|MirLua/Modules/result}} ====
;Example
{{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'''''
;Result
 
: Type: '''string'''
==== {{Ls|MirLua/Modules/result}} ====
;Example
{{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%')}}
[[Category:Tutorials (en)]]

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.

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