The Squirrel interpreter. See http://www.squirrel-lang.org/
samples/delegation.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 | PEntity <- { |
jhnwkmn | 0:97a4f8cc534c | 3 | name="noname" |
jhnwkmn | 0:97a4f8cc534c | 4 | pos={x=0,y=0,z=0} |
jhnwkmn | 0:97a4f8cc534c | 5 | type="entity" |
jhnwkmn | 0:97a4f8cc534c | 6 | //methamethod |
jhnwkmn | 0:97a4f8cc534c | 7 | _typeof=function() |
jhnwkmn | 0:97a4f8cc534c | 8 | { |
jhnwkmn | 0:97a4f8cc534c | 9 | return type; |
jhnwkmn | 0:97a4f8cc534c | 10 | } |
jhnwkmn | 0:97a4f8cc534c | 11 | } |
jhnwkmn | 0:97a4f8cc534c | 12 | |
jhnwkmn | 0:97a4f8cc534c | 13 | function PEntity::PrintPos() |
jhnwkmn | 0:97a4f8cc534c | 14 | { |
jhnwkmn | 0:97a4f8cc534c | 15 | ::print("x="+pos.x+" y="+pos.y+" z="+pos.z+"\n"); |
jhnwkmn | 0:97a4f8cc534c | 16 | } |
jhnwkmn | 0:97a4f8cc534c | 17 | |
jhnwkmn | 0:97a4f8cc534c | 18 | function PEntity::new(name,pos) |
jhnwkmn | 0:97a4f8cc534c | 19 | { |
jhnwkmn | 0:97a4f8cc534c | 20 | local newentity=clone ::PEntity; |
jhnwkmn | 0:97a4f8cc534c | 21 | if(name) |
jhnwkmn | 0:97a4f8cc534c | 22 | newentity.name=name; |
jhnwkmn | 0:97a4f8cc534c | 23 | if(pos) |
jhnwkmn | 0:97a4f8cc534c | 24 | newentity.pos=pos; |
jhnwkmn | 0:97a4f8cc534c | 25 | return newentity; |
jhnwkmn | 0:97a4f8cc534c | 26 | } |
jhnwkmn | 0:97a4f8cc534c | 27 | |
jhnwkmn | 0:97a4f8cc534c | 28 | PPlayer <- { |
jhnwkmn | 0:97a4f8cc534c | 29 | model="warrior.mdl" |
jhnwkmn | 0:97a4f8cc534c | 30 | weapon="fist" |
jhnwkmn | 0:97a4f8cc534c | 31 | health=100 |
jhnwkmn | 0:97a4f8cc534c | 32 | armor=0 |
jhnwkmn | 0:97a4f8cc534c | 33 | //overrides the parent type |
jhnwkmn | 0:97a4f8cc534c | 34 | type="player" |
jhnwkmn | 0:97a4f8cc534c | 35 | } |
jhnwkmn | 0:97a4f8cc534c | 36 | |
jhnwkmn | 0:97a4f8cc534c | 37 | function PPlayer::new(name,pos) |
jhnwkmn | 0:97a4f8cc534c | 38 | { |
jhnwkmn | 0:97a4f8cc534c | 39 | local p = clone ::PPlayer; |
jhnwkmn | 0:97a4f8cc534c | 40 | local newplayer = ::PEntity.new(name,pos); |
jhnwkmn | 0:97a4f8cc534c | 41 | newplayer.setdelegate(p); |
jhnwkmn | 0:97a4f8cc534c | 42 | return newplayer; |
jhnwkmn | 0:97a4f8cc534c | 43 | } |
jhnwkmn | 0:97a4f8cc534c | 44 | |
jhnwkmn | 0:97a4f8cc534c | 45 | local player=PPlayer.new("godzilla",{x=10,y=20,z=30}); |
jhnwkmn | 0:97a4f8cc534c | 46 | |
jhnwkmn | 0:97a4f8cc534c | 47 | ::print("PLAYER NAME"+player.name+"\n"); |
jhnwkmn | 0:97a4f8cc534c | 48 | ::print("ENTITY TYPE"+typeof player+"\n"); |
jhnwkmn | 0:97a4f8cc534c | 49 | |
jhnwkmn | 0:97a4f8cc534c | 50 | player.PrintPos(); |
jhnwkmn | 0:97a4f8cc534c | 51 | |
jhnwkmn | 0:97a4f8cc534c | 52 | player.pos.x=123; |
jhnwkmn | 0:97a4f8cc534c | 53 | |
jhnwkmn | 0:97a4f8cc534c | 54 | player.PrintPos(); |