| 1 | <h2>Full example</h2> |
| 2 | <pre><code> // source: http://www.squirrel-lang.org/#look |
| 3 | |
| 4 | local table = { |
| 5 | a = "10" |
| 6 | subtable = { |
| 7 | array = [1,2,3] |
| 8 | }, |
| 9 | [10 + 123] = "expression index" |
| 10 | } |
| 11 | |
| 12 | local array=[ 1, 2, 3, { a = 10, b = "string" } ]; |
| 13 | |
| 14 | foreach (i,val in array) |
| 15 | { |
| 16 | ::print("the type of val is"+typeof val); |
| 17 | } |
| 18 | |
| 19 | ///////////////////////////////////////////// |
| 20 | |
| 21 | class Entity |
| 22 | { |
| 23 | constructor(etype,entityname) |
| 24 | { |
| 25 | name = entityname; |
| 26 | type = etype; |
| 27 | } |
| 28 | |
| 29 | x = 0; |
| 30 | y = 0; |
| 31 | z = 0; |
| 32 | name = null; |
| 33 | type = null; |
| 34 | } |
| 35 | |
| 36 | function Entity::MoveTo(newx,newy,newz) |
| 37 | { |
| 38 | x = newx; |
| 39 | y = newy; |
| 40 | z = newz; |
| 41 | } |
| 42 | |
| 43 | class Player extends Entity { |
| 44 | constructor(entityname) |
| 45 | { |
| 46 | base.constructor("Player",entityname) |
| 47 | } |
| 48 | function DoDomething() |
| 49 | { |
| 50 | ::print("something"); |
| 51 | } |
| 52 | |
| 53 | } |
| 54 | |
| 55 | local newplayer = Player("da playar"); |
| 56 | |
| 57 | newplayer.MoveTo(100,200,300);</code></pre> |