~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/3rdparty/squirrel/samples/metamethods.nut

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
local base_vec={
 
3
        function _add(n)
 
4
        {
 
5
                return {
 
6
                        x=x+n.x,
 
7
                        y=y+n.y,
 
8
                        z=z+n.z,
 
9
                }
 
10
        }
 
11
        function _sub(n)
 
12
        {
 
13
                return {
 
14
                        x=x-n.x,
 
15
                        y=y-n.y,
 
16
                        z=z-n.z,
 
17
                }
 
18
        }
 
19
        function _div(n)
 
20
        {
 
21
                return {
 
22
                        x=x/n.x,
 
23
                        y=y/n.y,
 
24
                        z=z/n.z,
 
25
                }
 
26
        }
 
27
        function _mul(n)
 
28
        {
 
29
                return {
 
30
                        x=x*n.x,
 
31
                        y=y*n.y,
 
32
                        z=z*n.z,
 
33
                }
 
34
        }
 
35
        function _modulo(n)
 
36
        {
 
37
                return {
 
38
                        x=x%n,
 
39
                        y=y%n,
 
40
                        z=z%n,
 
41
                }
 
42
        }
 
43
        function _typeof() {return "vector";}
 
44
        function _get(key)
 
45
        {
 
46
                if(key==100)
 
47
                {
 
48
                        return test_field;
 
49
                }
 
50
        },
 
51
        function _set(key,val)
 
52
        {
 
53
                ::print("key = "+key+"\n");
 
54
                ::print("val = "+val+"\n")
 
55
                if(key==100)
 
56
                {
 
57
                        return test_field=val;
 
58
                }
 
59
        }
 
60
        test_field="nothing"
 
61
}
 
62
 
 
63
function vector(_x,_y,_z):(base_vec)
 
64
{
 
65
        return delegate base_vec : {x=_x,y=_y,z=_z }
 
66
}
 
67
////////////////////////////////////////////////////////////
 
68
 
 
69
local v1=vector(1.5,2.5,3.5);
 
70
local v2=vector(1.5,2.5,3.5);
 
71
 
 
72
local r=v1+v2;
 
73
 
 
74
 
 
75
foreach(i,val in r)
 
76
{
 
77
        print(i+" = "+val+"\n");
 
78
}
 
79
 
 
80
r=v1*v2;
 
81
 
 
82
foreach(i,val in r)
 
83
{
 
84
        print(i+" = "+val+"\n");
 
85
}
 
86
 
 
87
r=v1/v2;
 
88
 
 
89
foreach(i,val in r)
 
90
{
 
91
        print(i+" = "+val+"\n");
 
92
}
 
93
 
 
94
r=v1-v2;
 
95
 
 
96
foreach(i,val in r)
 
97
{
 
98
        print(i+" = "+val+"\n");
 
99
}
 
100
 
 
101
r=v1%2;
 
102
 
 
103
foreach(i,val in r)
 
104
{
 
105
        print(i+" = "+val+"\n");
 
106
}
 
107
 
 
108
print(v1[100]+"\n");
 
109
v1[100]="set SUCCEEDED";
 
110
print(v1[100]+"\n");
 
111
 
 
112
if(typeof v1=="vector")
 
113
        print("<SUCCEEDED>\n");
 
114
else
 
115
        print("<FAILED>\n");