-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
75 lines (58 loc) · 1.13 KB
/
test.js
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
/* javascript language executed through the lua VM */
// line comment
var function printf(format, ...) {
print(string.format(format, ...));
}
{
var a = 3;
if (a < 2)
printf("hello");
else if (a != 2) {
printf("hey !\n");
a += 3;
} else {
a++;
printf("yop\n");
}
a = (a ~= 2);
a = { hello, world };
Account = {
balance = 0,
Deposit = function(self, amount) {
self.balance += amount;
},
Print = function(self) {
printf("Account has %g\n", self.balance);
},
};
Account:Deposit(32);
Account:Print();
printf(nil || "hello world\n");
}
var function pr(pv)
{
print(v, pv);
}
for (_, v in pairs({ 1, 2, 3 }))
pr(v);
/* completely encapsulated account
* balance is both a private property and argument of the constructor */
local function CreateAccount(balance)
{
var public; // public interface
public = {
Deposit = function(amount) {
balance += amount;
},
Print = function() {
printf("Account has %g\n", balance);
},
};
return public;
}
local account = CreateAccount(0);
account.Deposit(32);
account.Print();
for (i = 1, 1000000, 1)
account.Deposit(32);
//Account:Deposit(32);