Files
@ r14248:a9050881acd7
Branch filter:
Location: cpp/openttd-patchpack/source/src/3rdparty/squirrel/samples/metamethods.nut
r14248:a9050881acd7
1.3 KiB
text/plain
(svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
local base_vec={
function _add(n)
{
return {
x=x+n.x,
y=y+n.y,
z=z+n.z,
}
}
function _sub(n)
{
return {
x=x-n.x,
y=y-n.y,
z=z-n.z,
}
}
function _div(n)
{
return {
x=x/n.x,
y=y/n.y,
z=z/n.z,
}
}
function _mul(n)
{
return {
x=x*n.x,
y=y*n.y,
z=z*n.z,
}
}
function _modulo(n)
{
return {
x=x%n,
y=y%n,
z=z%n,
}
}
function _typeof() {return "vector";}
function _get(key)
{
if(key==100)
{
return test_field;
}
},
function _set(key,val)
{
::print("key = "+key+"\n");
::print("val = "+val+"\n")
if(key==100)
{
return test_field=val;
}
}
test_field="nothing"
}
function vector(_x,_y,_z):(base_vec)
{
return delegate base_vec : {x=_x,y=_y,z=_z }
}
////////////////////////////////////////////////////////////
local v1=vector(1.5,2.5,3.5);
local v2=vector(1.5,2.5,3.5);
local r=v1+v2;
foreach(i,val in r)
{
print(i+" = "+val+"\n");
}
r=v1*v2;
foreach(i,val in r)
{
print(i+" = "+val+"\n");
}
r=v1/v2;
foreach(i,val in r)
{
print(i+" = "+val+"\n");
}
r=v1-v2;
foreach(i,val in r)
{
print(i+" = "+val+"\n");
}
r=v1%2;
foreach(i,val in r)
{
print(i+" = "+val+"\n");
}
print(v1[100]+"\n");
v1[100]="set SUCCEEDED";
print(v1[100]+"\n");
if(typeof v1=="vector")
print("<SUCCEEDED>\n");
else
print("<FAILED>\n");
|