The Squirrel interpreter. See http://www.squirrel-lang.org/
samples/class.nut@3:7268a3ceaffc, 2014-12-16 (annotated)
- Committer:
- jhnwkmn
- Date:
- Tue Dec 16 11:39:42 2014 +0000
- Revision:
- 3:7268a3ceaffc
- Parent:
- 0:97a4f8cc534c
Accepts \r as line terminator as well.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhnwkmn | 0:97a4f8cc534c | 1 | ////////////////////////////////////////////////////////////////////////////////// |
jhnwkmn | 0:97a4f8cc534c | 2 | ////////////////////////////////////////////////////////////////////////////////// |
jhnwkmn | 0:97a4f8cc534c | 3 | class BaseVector { |
jhnwkmn | 0:97a4f8cc534c | 4 | constructor(...) |
jhnwkmn | 0:97a4f8cc534c | 5 | { |
jhnwkmn | 0:97a4f8cc534c | 6 | if(vargv.len() >= 3) { |
jhnwkmn | 0:97a4f8cc534c | 7 | x = vargv[0]; |
jhnwkmn | 0:97a4f8cc534c | 8 | y = vargv[1]; |
jhnwkmn | 0:97a4f8cc534c | 9 | z = vargv[2]; |
jhnwkmn | 0:97a4f8cc534c | 10 | } |
jhnwkmn | 0:97a4f8cc534c | 11 | } |
jhnwkmn | 0:97a4f8cc534c | 12 | |
jhnwkmn | 0:97a4f8cc534c | 13 | |
jhnwkmn | 0:97a4f8cc534c | 14 | x = 0; |
jhnwkmn | 0:97a4f8cc534c | 15 | y = 0; |
jhnwkmn | 0:97a4f8cc534c | 16 | z = 0; |
jhnwkmn | 0:97a4f8cc534c | 17 | } |
jhnwkmn | 0:97a4f8cc534c | 18 | |
jhnwkmn | 0:97a4f8cc534c | 19 | class Vector3 extends BaseVector { |
jhnwkmn | 0:97a4f8cc534c | 20 | function _add(other) |
jhnwkmn | 0:97a4f8cc534c | 21 | { |
jhnwkmn | 0:97a4f8cc534c | 22 | if(other instanceof this.getclass()) |
jhnwkmn | 0:97a4f8cc534c | 23 | return ::Vector3(x+other.x,y+other.y,z+other.z); |
jhnwkmn | 0:97a4f8cc534c | 24 | else |
jhnwkmn | 0:97a4f8cc534c | 25 | throw "wrong parameter"; |
jhnwkmn | 0:97a4f8cc534c | 26 | } |
jhnwkmn | 0:97a4f8cc534c | 27 | function Print() |
jhnwkmn | 0:97a4f8cc534c | 28 | { |
jhnwkmn | 0:97a4f8cc534c | 29 | ::print(x+","+y+","+z+"\n"); |
jhnwkmn | 0:97a4f8cc534c | 30 | } |
jhnwkmn | 0:97a4f8cc534c | 31 | } |
jhnwkmn | 0:97a4f8cc534c | 32 | |
jhnwkmn | 0:97a4f8cc534c | 33 | local v0 = Vector3(1,2,3) |
jhnwkmn | 0:97a4f8cc534c | 34 | local v1 = Vector3(11,12,13) |
jhnwkmn | 0:97a4f8cc534c | 35 | local v2 = v0 + v1; |
jhnwkmn | 0:97a4f8cc534c | 36 | v2.Print(); |
jhnwkmn | 0:97a4f8cc534c | 37 | |
jhnwkmn | 0:97a4f8cc534c | 38 | FakeNamespace <- { |
jhnwkmn | 0:97a4f8cc534c | 39 | Utils = {} |
jhnwkmn | 0:97a4f8cc534c | 40 | } |
jhnwkmn | 0:97a4f8cc534c | 41 | |
jhnwkmn | 0:97a4f8cc534c | 42 | class FakeNamespace.Utils.SuperClass { |
jhnwkmn | 0:97a4f8cc534c | 43 | constructor() |
jhnwkmn | 0:97a4f8cc534c | 44 | { |
jhnwkmn | 0:97a4f8cc534c | 45 | ::print("FakeNamespace.Utils.SuperClass") |
jhnwkmn | 0:97a4f8cc534c | 46 | } |
jhnwkmn | 0:97a4f8cc534c | 47 | } |
jhnwkmn | 0:97a4f8cc534c | 48 | |
jhnwkmn | 0:97a4f8cc534c | 49 | local testy = FakeNamespace.Utils.SuperClass(); |