diff options
author | Martin Peach <mrpeach@users.sourceforge.net> | 2011-03-15 20:53:57 +0000 |
---|---|---|
committer | Martin Peach <mrpeach@users.sourceforge.net> | 2011-03-15 20:53:57 +0000 |
commit | 267170167d52cab9e97f879d9127a1cf04f6bb58 (patch) | |
tree | 00260a90ce6472e34c5eff41602af57595c8830d /examples/complex.lua |
This is a version of Claude Heiland-Allen's lua for Pd. The objects are named pdlua and pdluax instead of lua and luax. So far it seems to work on linux.svn2git-root
svn path=/trunk/externals/pdlua/; revision=15030
Diffstat (limited to 'examples/complex.lua')
-rw-r--r-- | examples/complex.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/complex.lua b/examples/complex.lua new file mode 100644 index 0000000..62d6d0e --- /dev/null +++ b/examples/complex.lua @@ -0,0 +1,30 @@ +local P = {} +if _REQUIREDNAME == nil then + complex = P +else + _G[_REQUIREDNAME] = P +end + +-- imports +-- local sqrt = math.sqrt + +-- no more external access after this point +setfenv(1, P) + +function new (r, i) return {r=r, i=i} end + +i = new(0, 1) + +function add(c1, c2) + return new(c1.r + c2.r, c1.i + c2.i) +end + +function sub(c1, c2) + return new(c1.r - c2.r, c1.i - c2.i) +end + +function mul(c1, c2) + return new(c1.r * c2.r - c1.i * c2.i, c1.r * c2.i + c1.i * c2.r) +end + +return P |