forked from bonzini/smalltalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cobjects.st
97 lines (79 loc) · 2.5 KB
/
cobjects.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"======================================================================
|
| Test CObject operations
|
|
======================================================================"
"======================================================================
|
| Copyright (C) 2002, 2005 Free Software Foundation.
| Written by Paolo Bonzini
|
| This file is part of GNU Smalltalk.
|
| GNU Smalltalk is free software; you can redistribute it and/or modify it
| under the terms of the GNU General Public License as published by the Free
| Software Foundation; either version 2, or (at your option) any later version.
|
| GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
| FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
| details.
|
| You should have received a copy of the GNU General Public License along with
| GNU Smalltalk; see the file COPYING. If not, write to the Free Software
| Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
======================================================================"
| ca buf |
ca := (CStringType arrayType: 1) new.
buf := (CCharType arrayType: 10) new.
buf at: 0 put: $a.
buf at: 1 put: $s.
buf at: 2 put: $d.
buf at: 3 put: 0 asCharacter.
ca at: 0 put: buf.
^ca at: 0!
| ca |
ca := (CStringType arrayType: 1) new.
ca at: 0 put: (CString value: 'asd').
^ca at: 0!
Smalltalk at: #CA put: nil!
CA := (CStringType arrayType: 2) new.
CA at: 0 put: (CString value: 'asd').
CA at: 1 put: (CString value: 'dsa')!
^CA at: 0!
^CA at: 1!
^(CA addressAt: 0) class!
^(CA addressAt: 0) value!
^(CA addressAt: 1) value!
^(CA + 1) class!
^(CA + 1) at: -1!
^(CA + 1) at: 0!
^(CA + 1) - CA!
Smalltalk at: #CP put: nil!
CP := CStringType ptrType new.
CP value: CA.
^CP value at: 0!
^CP value at: 1!
^(CP value addressAt: 0) class!
^(CP value addressAt: 0) value!
^(CP value addressAt: 1) value!
^(CP value + 1) class!
^(CP value + 1) at: -1!
^(CP value + 1) at: 0!
^(CP value + 1) - CA!
!Object methodsFor: 'C call-outs'!
testCallin
<cCall: 'testCallin' returning: #void args: #(#selfSmalltalk)>!
testCString: cString
<cCall: 'testCString' returning: #void args: #(#cObject)>!
testCObjectPtr: cObject
<cCall: 'testCObjectPtr' returning: #void args: #(#cObjectPtr)>! !
true testCallin!
nil testCString: (CString value: 'this is a test')!
| cObject |
cObject := CCharType new.
nil testCObjectPtr: cObject.
^cObject asString!
" ### need a lot more!"