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

« back to all changes in this revision

Viewing changes to src/3rdparty/squirrel/samples/methcall.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
/*translation of the methcall test from The Great Computer Language Shootout
 
2
*/
 
3
 
 
4
Toggle <- {
 
5
        bool=null
 
6
}
 
7
 
 
8
function Toggle::value() {
 
9
        return bool;
 
10
}
 
11
 
 
12
function Toggle::activate() {
 
13
        bool = !bool;
 
14
        return this;
 
15
}
 
16
 
 
17
function Toggle::new(startstate) {
 
18
        local newo=clone this;
 
19
        newo.bool = startstate;
 
20
        return newo;
 
21
}
 
22
 
 
23
NthToggle <- {
 
24
        count_max=null
 
25
        count=0
 
26
}
 
27
 
 
28
function NthToggle::new(start_state,max_counter)
 
29
{
 
30
        local newo=delegate ::Toggle.new(start_state) : clone this;
 
31
        newo.count_max <- max_counter
 
32
        return newo;
 
33
}
 
34
 
 
35
function NthToggle::activate ()
 
36
{
 
37
        count+=1
 
38
    if (count >= count_max) {
 
39
      bool = !bool;
 
40
      count = 0;
 
41
    }
 
42
    return this;
 
43
}
 
44
 
 
45
 
 
46
local n = ARGS.len()!=0?ARGS[0].tointeger():1
 
47
 
 
48
local val = 1;
 
49
local toggle = Toggle.new(val);
 
50
for (local i=0; i<n; i+=1) {
 
51
  val = toggle.activate().value();
 
52
 
 
53
}
 
54
print(toggle.value() ? "true\n" : "false\n");
 
55
 
 
56
val = 1;
 
57
local ntoggle = NthToggle.new(val, 3);
 
58
for (local i=0; i<n; i+=1) {
 
59
  val = ntoggle.activate().value();
 
60
}
 
61
print(ntoggle.value() ? "true\n" : "false\n");