Mercurial > repos > tabletprog
comparison modules/string.tp @ 147:4c96a393103e
Add support for receiving data from a socket
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 09 Aug 2013 04:57:21 -0700 |
parents | 474f17ebaaa0 |
children | 7dfa4481deb0 |
comparison
equal
deleted
inserted
replaced
146:d8f92ebf1ff6 | 147:4c96a393103e |
---|---|
1 #{ | 1 #{ |
2 llProperty: len withType: uint32_t | 2 llProperty: len withType: uint32_t |
3 llProperty: bytes withType: uint32_t | 3 llProperty: bytes withType: uint32_t |
4 llProperty: data withType: (char ptr) | 4 llProperty: data withType: (char ptr) |
5 | 5 |
6 llMessage: length withVars: { | 6 llMessage: length withVars: { |
7 intret <- (obj_int32 ptr) | 7 intret <- (obj_int32 ptr) |
8 } andCode: { | 8 } andCode: { |
9 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 | 9 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
10 intret num!: len | 10 intret num!: len |
11 intret | 11 intret |
12 } | 12 } |
13 | 13 |
14 llMessage: byte_length withVars: { | 14 llMessage: byte_length withVars: { |
15 intret <- (obj_int32 ptr) | 15 intret <- (obj_int32 ptr) |
16 } andCode: { | 16 } andCode: { |
17 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 | 17 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
18 intret num!: bytes | 18 intret num!: bytes |
19 intret | 19 intret |
20 } | 20 } |
21 | 21 |
22 llMessage: EQ_ withVars: { | 22 llMessage: EQ_ withVars: { |
23 argb <- (string ptr) | 23 argb <- (string ptr) |
24 } andCode: :argb { | 24 } andCode: :argb { |
25 if: len = (argb len) && bytes = (argb bytes) && (not: (memcmp: data (argb data) bytes)) { | 25 if: len = (argb len) && bytes = (argb bytes) && (not: (memcmp: data (argb data) bytes)) { |
26 true | 26 true |
27 } | 27 } |
28 } | 28 } |
29 | 29 |
30 llMessage: NEQ_ withVars: { | 30 llMessage: NEQ_ withVars: { |
31 argb <- (string ptr) | 31 argb <- (string ptr) |
32 } andCode: :argb { | 32 } andCode: :argb { |
33 if: len != (argb len) || bytes != (argb bytes) || (memcmp: data (argb data) bytes) { | 33 if: len != (argb len) || bytes != (argb bytes) || (memcmp: data (argb data) bytes) { |
34 true | 34 true |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 llMessage: print withVars: {} andCode: { | 38 llMessage: print withVars: {} andCode: { |
39 fwrite: data 1 bytes stdout | 39 fwrite: data 1 bytes stdout |
40 self | 40 self |
41 } | 41 } |
42 | 42 |
43 llMessage: string withVars: {} andCode: { | 43 llMessage: string withVars: {} andCode: { |
44 self | 44 self |
45 } | 45 } |
46 | 46 |
47 llMessage: CAT_ withVars: { | 47 llMessage: CAT_ withVars: { |
48 argbo <- (object ptr) | 48 argbo <- (object ptr) |
49 argb <- (string ptr) | 49 argb <- (string ptr) |
50 out <- (string ptr) | 50 out <- (string ptr) |
51 } andCode: :argbo { | 51 } andCode: :argbo { |
56 out data!: (GC_MALLOC_ATOMIC: (out bytes) + 1) | 56 out data!: (GC_MALLOC_ATOMIC: (out bytes) + 1) |
57 memcpy: (out data) data bytes | 57 memcpy: (out data) data bytes |
58 memcpy: (out data) + bytes (argb data) (argb bytes) + 1 | 58 memcpy: (out data) + bytes (argb data) (argb bytes) + 1 |
59 out | 59 out |
60 } | 60 } |
61 | 61 |
62 llMessage: byte withVars: { | 62 llMessage: byte withVars: { |
63 index <- (obj_int32 ptr) | 63 index <- (obj_int32 ptr) |
64 intret <- (obj_int32 ptr) | 64 intret <- (obj_int32 ptr) |
65 } andCode: :index { | 65 } andCode: :index { |
66 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 | 66 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
67 intret num!: (if: (index num) < bytes { data get: (index num) } else: {0}) | 67 intret num!: (if: (index num) < bytes { data get: (index num) } else: {0}) |
68 intret | 68 intret |
69 } | 69 } |
70 | 70 |
71 llMessage: int32 withVars: { | 71 llMessage: int32 withVars: { |
72 intret <- (obj_int32 ptr) | 72 intret <- (obj_int32 ptr) |
73 } andCode: { | 73 } andCode: { |
74 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 | 74 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
75 intret num!: (atoi: data) | 75 intret num!: (atoi: data) |
76 intret | 76 intret |
77 } | 77 } |
78 | 78 |
79 llMessage: hash withVars: { | 79 llMessage: hash withVars: { |
80 intret <- (obj_int32 ptr) | 80 intret <- (obj_int32 ptr) |
81 i <- uint32_t | 81 i <- uint32_t |
82 } andCode: { | 82 } andCode: { |
83 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 | 83 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
91 } | 91 } |
92 intret num!: (intret num) xor bytes | 92 intret num!: (intret num) xor bytes |
93 } | 93 } |
94 intret | 94 intret |
95 } | 95 } |
96 | |
97 isInteger? <- { false } | |
96 } | 98 } |