2010-12-28 02:17:20 -08:00
|
|
|
<?xml version="1.0" encoding="UTF-8" ?>
|
|
|
|
<!DOCTYPE article [
|
|
|
|
<!ENTITY % medit-defines SYSTEM "medit-defines.ent">
|
|
|
|
%medit-defines;
|
|
|
|
]>
|
2011-01-22 17:40:22 -08:00
|
|
|
<chapter id="chapter-script-lua">
|
2011-01-22 22:12:20 -08:00
|
|
|
<?dbhtml filename="lua-moo.html"?>
|
2010-12-28 02:17:20 -08:00
|
|
|
<title>&medit; Lua API</title>
|
|
|
|
|
2011-01-22 17:40:22 -08:00
|
|
|
<sect1 id="section-script-lua-introduction">
|
2010-12-28 02:17:20 -08:00
|
|
|
<title>Introduction</title>
|
|
|
|
<para>Lua scripts running in &medit; have access to its
|
2011-01-22 17:40:22 -08:00
|
|
|
functionality through the <code>moo</code> package.</para>
|
2010-12-28 02:17:20 -08:00
|
|
|
<warning>
|
|
|
|
Functions which are not documented here may or may not work differently in
|
|
|
|
the future and they may disappear without notice. Contact the author if you
|
|
|
|
need functions which are not present here.
|
|
|
|
</warning>
|
|
|
|
</sect1>
|
|
|
|
|
2011-01-22 17:40:22 -08:00
|
|
|
<sect1 id="section-script-lua-object-model">
|
2010-12-28 02:17:20 -08:00
|
|
|
<title>&medit; object model</title>
|
2011-12-29 01:47:32 -08:00
|
|
|
<para>&medit; uses a very simple object model where its objects are
|
2010-12-28 02:17:20 -08:00
|
|
|
represented as user data in Lua and methods are provided via metatable
|
|
|
|
shared by all objects of all "classes". Method dispatch is dynamic,
|
|
|
|
i.e. metatable does not contain functions which correspond to methods,
|
|
|
|
and <code>obj:method</code> returns a function object which knows which
|
|
|
|
method on which object it is going to call.</para>
|
|
|
|
<para>This manual lists and talks about "classes", but it is merely
|
|
|
|
to avoid complicated terminology. When we say that an object belongs
|
|
|
|
to or is an instance of a class <code>Foo</code>, it just means that
|
|
|
|
it has methods listed in manual section for class <code>Foo</code>
|
|
|
|
and methods of parent classes, if any.</para>
|
|
|
|
<note>
|
|
|
|
To call a method, you can use both <code>obj:method(args)</code>
|
|
|
|
and <code>obj.method(args)</code>.
|
|
|
|
</note>
|
|
|
|
</sect1>
|
|
|
|
|
2011-01-22 17:40:22 -08:00
|
|
|
<sect1 id="section-script-lua-notations">
|
2010-12-28 02:17:20 -08:00
|
|
|
<title>Notations</title>
|
|
|
|
<para>This manual uses the following conventions:</para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>Optional parameters</term>
|
|
|
|
<listitem>
|
2011-01-25 01:55:18 -08:00
|
|
|
<programlisting>func(arg1=val1, arg2=val, arg3=val3)</programlisting>
|
2010-12-28 02:17:20 -08:00
|
|
|
<code><parameter>arg</parameter>=val</code> means that
|
|
|
|
parameter <parameter>arg</parameter> is optional, and function receives
|
2011-01-25 00:28:57 -08:00
|
|
|
value <code>val</code> if it's missing. Not all parameters are necessarily
|
|
|
|
optional. For example, <programlisting>insert_text(text, where=nil)</programlisting>
|
2010-12-28 02:17:20 -08:00
|
|
|
means that <parameter>text</parameter> may not be missing or <constant>nil</constant>
|
|
|
|
(unless documentation says otherwise), and <parameter>where</parameter> is optional.
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>Keyword parameters</term>
|
|
|
|
<listitem>
|
2011-01-25 01:55:18 -08:00
|
|
|
<programlisting>func{arg1, arg2, kwarg1=kwval1, kwarg2=kwval2}</programlisting>
|
|
|
|
This means that function can be called in an alternative way: actual parameters are
|
|
|
|
taken from the single table parameter, which must be a dictionary with keys
|
|
|
|
<parameter>kwarg1</parameter>, <parameter>kwarg2</parameter>, etc., and whose array part
|
|
|
|
must contain exactly as many values as there are non-optional arguments. Similarly
|
|
|
|
to regular parameters, <code><parameter>kwarg</parameter>=kwval</code> means that
|
|
|
|
<parameter>kwarg</parameter> is optional. For example, above function can be called
|
|
|
|
as follows.
|
|
|
|
<programlisting>
|
|
|
|
<!-- -->func{1, 2, kwarg1='foo'} -- equivalent to func(1, 2, 'foo')
|
|
|
|
<!-- -->func{3, 4, kwarg2='bar'} -- equivalent to func(3, 4, kwval1, 'bar')
|
|
|
|
<!-- -->func{5, 6, kwarg2='baz', kwarg1='bud', } -- equivalent to func(5, 6, 'bud', 'baz')</programlisting>
|
|
|
|
This is similar to Python keyword arguments (with the difference that keyword arguments
|
|
|
|
may be used only if function is documented to support them).
|
2010-12-28 02:17:20 -08:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
|
|
|
|
</sect1>
|
|
|
|
###GENERATED###
|
2011-01-22 17:40:22 -08:00
|
|
|
</chapter>
|