aboutsummaryrefslogtreecommitdiff
path: root/doc/luax.txt
blob: dbaadb46bdeaf3e75c26a258d290ccc32544b2a9 (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
pdluax
====

The pdluax class allows "volatile" loading of Lua source code files
that define Pd object behaviour.

The [pdluax foo] object loads "foo.pd_luax" at object creation time.


Advantages
----------

+ You can edit "foo.pd_luax" and new [pdluax foo] objects will reflect
  the changes in the file.

+ Good for rapid development/testing cycles.

+ Good for live coding.

+ No need to restart Pd if you made a little mistake.


Disadvantages
-------------

- Reloading the file each time is slower.

- Syntax is different to the syntax expected by the Lua loader
  (see below for discussion).

- There is no "reload" functionality, so you can have multiple
  objects called [pdluax foo] but that have different behaviours.

- Data shared between objects must be accessible globally.

- The above two points mean some mistakes/changes mean you have
  to restart Pd anyway.


How To Write Code For pdluax
--------------------------

The last expression/statement in the file should be of the form:

    return function (self, sel, atoms)
      -- code here
    end

This function is executed in the context of the 'initialize'
method of the pdluax class, and has the same arguments:

    'self' is the object to be created.
    'sel' is the name of the class.
    'atoms' are the creation arguments.

To add methods to the new object you need to add code inside
the returned function.  There are two syntaxes for this:

    function self:in_1_float(f) ... end

or

    self.in_1_float = function(self, f) ... end

If using the second form, remember the self argument.

If you need a shared state between objects, you need to use a
global name.  Try to pick something unique to avoid conflicts
with other scripts.  You also need to ensure that you don't
clobber this state - remember the script can be executed more
than once.