Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.0 KiB

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