document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // Class init
  2. TRANSPORT = []
  3. INDEX = -1
  4.  
  5. // defining class functions:
  6. func SetType(trans, ...):
  7.    trans.Type = vargs(1)
  8.    return trans
  9. end
  10.  
  11. func GetType(trans, ...):
  12.    return trans.Type
  13. end
  14.  
  15. func GetSpeed(trans, ...):
  16.    return trans.Speed
  17. end
  18.  
  19. func GetAcc(trans, ...):
  20.    return trans.Acc
  21. end
  22.  
  23. func Stop(trans, ...):
  24.    trans.Speed = 0
  25.    trans.Acc = 0
  26.    return trans
  27. end
  28.    
  29. func Go(trans, speed, acc):
  30.    trans.Speed = speed
  31.    trans.Acc = acc
  32.    return trans
  33. end
  34.  
  35. //main class
  36. func transport(op, ...):
  37.    temp = op(TRANSPORT[INDEX], vargs(1), vargs(2))
  38.    if temp !== [] then
  39.       return temp
  40.    else:
  41.       TRANSPORT[INDEX] = temp
  42.       return TRANSPORT[INDEX]
  43.    end
  44. end
  45.  
  46. // function to create a new class
  47. func new_transport():
  48.    INDEX++
  49.    TRANSPORT[INDEX] = []
  50.    TRANSPORT[INDEX].Type = void
  51.    TRANSPORT[INDEX].Speed = void
  52.    TRANSPORT[INDEX].Acc = void
  53.    
  54.    return INDEX
  55. end
  56.  
  57. // function to switch the active class:
  58. func Select_Transport(index):
  59.    INDEX = index
  60. end
  61.  
  62. // to Job!
  63. AirPlane = new_transport()
  64.  
  65. transport(SetType, "airplane")
  66. puts("transport mean N1: "+transport(GetType))
  67. transport(Go, 300, 30)
  68. puts("speed: "+transport(GetSpeed))
  69. puts("acceleration: "+transport(GetAcc))
  70.  
  71.  
  72. // another class!
  73. Schoolbus = new_transport()
  74.  
  75. transport(SetType, "SchoolBus")
  76. puts("transport mean N2: "+transport(GetType))
  77. transport(Go, 40, 10)
  78. puts("speed: "+transport(GetSpeed))
  79. puts("acceleration: "+transport(GetAcc))
  80. transport(Stop)
  81.  
  82. // switch class
  83. Select_Transport(AirPlane)
  84.  
  85. puts("back to "+transport(GetType))
  86. puts("speed: "+transport(GetSpeed))
  87. puts("acceleration: "+transport(GetAcc))
  88.  
  89. // switch again
  90. Select_Transport(Schoolbus)
  91.  
  92. puts("back to "+transport(GetType))
  93. puts("speed: "+transport(GetSpeed))
  94. puts("acceleration: "+transport(GetAcc))
  95.  
  96. /*
  97. === console output: ===
  98. transport mean N1: airplane
  99. speed: 300
  100. acceleration: 30
  101. transport mean N2: SchoolBus
  102. speed: 40
  103. acceleration: 10
  104. back to airplane
  105. speed: 300
  106. acceleration: 30
  107. back to SchoolBus
  108. speed: 0
  109. acceleration: 0
  110. */
');