summaryrefslogtreecommitdiff
path: root/opcodes/lua_exec.xml
blob: 7af0d926ccb47f7c7aa5ff1b1a6f78f0ca441f6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<refentry id="lua_exec">
    <indexterm id="Indexlua_exec">
        <primary>
            lua_exec
        </primary>
    </indexterm>
    <refentryinfo><title>Lua Opcodes</title></refentryinfo>
    <refmeta>
        <refentrytitle>
            lua_exec
        </refentrytitle>
    </refmeta>

    <refnamediv>
        <refname>
            lua_exec
        </refname>
        <refpurpose>
            Executes an arbitrary block of Lua code from the Csound orchestra.
        </refpurpose>
    </refnamediv>

    <refsect1>
        <title>
            Description
        </title>
        <para>
            Executes an arbitrary block of Lua code from the Csound orchestra. 
            The code is executed at initialization time, typically from the 
            orchestra header. 
        </para>
    </refsect1>

    <refsect1>
        <title>
            Syntax
        </title>
        <synopsis><command>lua_exec</command> Sluacode</synopsis>
    </refsect1>

    <refsect1>
        <title>
            Initialization
        </title>
        <para>
            <emphasis>Sluacode</emphasis> -- A block of Lua code, of any 
            length. Multi-line blocks may be enclosed in 
            double braces (i.e. <literal>{{ }}</literal>). This code is 
            evaluated once at initialization time, typically from the 
            orchestra header. Global and local variables, functions, 
            tables, and classes may be declared and defined. Objects defined 
            at global Lua scope remain in scope throughout the performance, 
            and are visible to any other Lua code in the same Csound thread.
        </para>
        <para>
            The running instance of Csound is stored as a 
            Lua lightuserdata in a global variable <literal>csound</literal>. 
            This can be passed to any Csound API function.  One use of this 
            would be to generate a score using Lua in the orchestra header, 
            and schedule the events for performance using <literal>csoundInputMessage</literal>.
        </para>
        <note>
            <para>
               By default, all objects defined in Lua are defined at global 
               scope. In order to ensure that objects are confined to their 
               own block of code, that is to ensure that the object is visible 
               only in lexical scope, the object must be declared as local. 
               This is the feature of Lua that beginners tend to find the most 
               troublesome.
            </para> 
            <para>
               Another thing to look out for is that Lua arrays use 1-based 
               indexing, not the 0-based indexing used in C and many other 
               programming languages.
            </para>
        </note>

    </refsect1>

    <refsect1>
        <title>
            See Also
        </title>
        <para>
            <link linkend="lua_opdef"><citetitle>lua_opdef</citetitle></link>, 
            <link linkend="lua_opcall"><citetitle>lua_opcall</citetitle></link>. 
        </para>
    </refsect1>
    
    <refsect1>
        <title>
            Credits
        </title>
        <para>
            By: &namemichael; 2011
        </para>
        <para>
            New in Csound version 5.13.2
        </para>
    </refsect1>
</refentry>