Skip to content
Snippets Groups Projects
Commit 620d90b3 authored by pcherenkov's avatar pcherenkov
Browse files

bug923715: init.lua documented

parent 62e0d47a
No related branches found
No related tags found
No related merge requests found
......@@ -259,7 +259,7 @@ lsn:4 tm:1301572313.691 t:65534 127.0.0.1:52728 UPDATE_FIELDS n:0flags:00000000
</row>
<row>
<entry>work_dir</entry>
<entry xml:id="work_dir" xreflabel="work_dir">work_dir</entry>
<entry>string</entry>
<entry>""</entry>
<entry>no</entry>
......
......@@ -20,7 +20,7 @@
</para>
</blockquote>
<para>
Procedures can be invoked both from the administrative
Procedures can be invoked from the administrative
console and using the binary protocol, for example:
<programlisting><computeroutput>localhost> lua function f1() return 'hello' end
---
......@@ -57,6 +57,43 @@ localhost> lua "hello".." world"
...
</computeroutput></programlisting>
</para>
<para>
Lua procedures could also be called at the time of initialization
using a dedicated <emphasis>init.lua</emphasis> script,
located in <olink targetptr="work_dir" />.
An example of such a script is given below:
<programlisting>
<![CDATA[
-- Importing expirationd module
dofile("expirationd.lua")
function is_expired(args, tuple)
if tuple == nil then
return true
end
if #tuple <= args.field_no then
return true
end
field = tuple[args.field_no]
if field == nil or #field ~= 4 then
return true
end
local current_time = os.time()
local tuple_ts = box.unpack("i", field)
return current_time >= tuple_ts + args.ttl
end
-- Run task
expirationd.run_task("exprd space 0", 0, is_expired, nil,
{ field_no = 1, ttl = 30 * 60 })
]]>
</programlisting>
</para>
<para>
There is a single global instance of Lua interpreter, which is
shared across all connections. Anything prefixed with
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment