Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
tarantool
Commits
7b0177cc
Commit
7b0177cc
authored
13 years ago
by
Konstantin Osipov
Browse files
Options
Downloads
Patches
Plain Diff
User guide: add more data on stored programs.
parent
205f0caa
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/user/stored-programs.xml
+35
-20
35 additions, 20 deletions
doc/user/stored-programs.xml
with
35 additions
and
20 deletions
doc/user/stored-programs.xml
+
35
−
20
View file @
7b0177cc
...
...
@@ -9,7 +9,8 @@
<title>
Writing stored procedures in Lua
</title>
<blockquote>
<para>
Lua is a light-weight, multi-paradigm embeddable language.
<link
xlink:href=
"http://www.lua.org"
>
Lua
</link>
is a light-weight, multi-paradigm, embeddable language.
Stored procedures in Lua can be used to implement
data manipulation patterns or data structures. A
server-side procedure written in Lua can select and modify
...
...
@@ -18,13 +19,10 @@
alter and drop Lua procedures.
</para>
</blockquote>
<para>
Procedures can be invoked both from the administrative
console and using the binary protocol, for example:
<programlisting>
<computeroutput>
localhost> lua function f1() return 'hello' end
<programlisting><computeroutput>
localhost> lua function f1() return 'hello' end
---
...
localhost> call f1()
...
...
@@ -34,7 +32,7 @@ Found 1 tuple:
</programlisting>
In the language of the administrative console
<olink
targetptr=
"lua-command"
/>
evaluates an arbitrary
Lua chunk.
"
CALL
"
is the SQL standard statement used
Lua chunk. CALL is the SQL standard statement used
to represent CALL command of the binary
protocol.
In the example above, a Lua procedure is first defined
...
...
@@ -45,9 +43,7 @@ Found 1 tuple:
administrative console, the newly created
<code
language=
"Pascal"
>
function f1()
</code>
can be called there too:
<programlisting>
<computeroutput>
localhost> lua f1()
<programlisting><computeroutput>
localhost> lua f1()
---
- hello
...
...
...
@@ -59,18 +55,25 @@ localhost> lua "hello".." world"
---
- hello world
...
</computeroutput>
</programlisting>
</computeroutput></programlisting>
</para>
<para>
There is a single global instance of Lua interpreter, which is
shared across all connections. Anything prefixed with
<code>
lua
</code>
on the administrative console is sent
directly to this interpreter. This way it's possible to define
and drop stored procedures at run time, without having to
restart the server: any change of the interpreter state is
immediately available to all client connections.
</para>
<para>
Each connection, however, is running in its own Lua
<emphasis>
coroutine
</emphasis>
—
a mechanism, akin to
Tarantool
<emphasis>
fibers
</emphasis>
. A coroutine has its
own execution stack and a Lua
<emphasis>
closure
</emphasis>
—
set of local variables and definitions.
</para>
<para>
There is a single global Lua interpreter state, which is
shared across all connections. Each connection, however, is
running in its own Lua
<emphasis>
thread
</emphasis>
—
a mechanism, akin to
Tarantool
<emphasis>
fibers
</emphasis>
.
Anything prefixed with
<code>
lua
</code>
on the administrative console
is sent directly to the interpreter. In the binary protocol,
however, it is only possible to invoke Lua functions, but not
define or modify them.
A special command code designates invocation of a stored
program in the binary protocol. The tuple, sent as argument
of the command, is passed into the stored procedure, each
...
...
@@ -78,11 +81,23 @@ localhost> lua "hello".." world"
procedure. As long as currently Tarantool tuples are
type-agnostic, Lua strings are chosen as the transport media
between the server and the interpreter.
In the binary protocol, it is only possible to
<emphasis
role=
"strong"
>
invoke
</emphasis>
Lua functions, but not
<emphasis
role =
"strong"
>
define
</emphasis>
or
<emphasis
role=
"strong"
>
modify
</emphasis>
them.
</para>
<para>
In addition to conventional method invocation,
Lua provides object-oriented syntax. Access to the latter is also
only available on the administrative console.
</para>
<para>
Every value, returned from a stored function by means of
<code>
return
</code>
clause, is converted to Tarantool/Box tuple
and sent back to the client in binary form.
and sent back to the client in binary form. Tuples are
returned as such; an atom, such as a string or an integer, is
converted to a tuple that has only one field. In case of
<emphasis>
Lua table
</emphasis>
, the resulting tuple contains
only table values, but not keys.
</para>
<para>
When a function in Lua terminates with an error, it is
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment