lua_exec

lua_exec — Executes an arbitrary block of Lua code from the Csound orchestra.

[Note] Note
plugin: Requires lua plugin

Description

Executes an arbitrary block of Lua code from the Csound orchestra. The code is executed at initialization time, typically from the orchestra header.

Syntax

lua_exec Sluacode

Initialization

Sluacode -- A block of Lua code, of any length. Multi-line blocks may be enclosed in double braces (i.e. {{ }}). 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.

The running instance of Csound is stored as a Lua lightuserdata in a global variable csound. 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 csoundInputMessage.

[Note] Note

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.

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.

See Also

lua_opdef, lua_opcall.

Credits

By: Michael Gogins 2011

New in Csound version 5.13.2