Skip to content
Snippets Groups Projects
Commit cde936ba authored by Marek Vavruša's avatar Marek Vavruša
Browse files

doc: improved Lua modules doc

parent dcd89700
Branches
Tags
No related merge requests found
......@@ -139,8 +139,21 @@ The modules follow the `Lua way <http://lua-users.org/wiki/ModuleDefinition>`_,
return counter
.. tip:: The API functions may return an integer value just like in other languages, but they may also return a coroutine that will be continued asynchronously. A good use case for this approach is is a deferred initialization,
e.g. loading a chunks of data or waiting for I/O.
.. tip:: The API functions may return an integer value just like in other languages, but they may also return a coroutine that will be continued asynchronously. A good use case for this approach is is a deferred initialization, e.g. loading a chunks of data or waiting for I/O.
.. code-block:: lua
function counter.init(module)
counter.total = 0
counter.last = 0
counter.failed = 0
return coroutine.create(function ()
for line in io.lines('/etc/hosts') do
load(module, line)
coroutine.yield()
end
end)
end
The created module can be then loaded just like any other module, except it isn't very useful since it
doesn't provide any layer to capture events. The Lua module can however provide a processing layer, just
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment