2 Little Smalltalk, Version 5
4 Copyright (C) 1987-2005 by Timothy A. Budd
5 Copyright (C) 2007 by Charles R. Childers
6 Copyright (C) 2005-2007 by Danny Reinhold
7 Copyright (C) 2010 by Ketmar // Vampire Avalon
9 ============================================================================
10 This license applies to the virtual machine and to the initial image of
11 the Little Smalltalk system and to all files in the Little Smalltalk
12 packages except the files explicitly licensed with another license(s).
13 ============================================================================
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the 'Software'), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
21 The above copyright notice and this permission notice shall be included in
22 all copies or substantial portions of the Software.
24 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 DEALINGS IN THE SOFTWARE.
40 EXTPRIM FFIResolveName
42 EXTPRIM FFICloseHandle
50 Object subclass: FFI [
51 | handle name functions |
69 functions <- Dictionary new
74 path <- PathName new: theName.
75 path replaceOrAddSuffix: System suffixForDLL.
91 functions: theFunctions [
92 functions <- theFunctions
99 resolveFunction: theName [
100 ^<FFIResolveName handle (theName printString)>
105 func <- self resolveFunction: theName.
106 functions at: theName put: func.
110 ^functions at: theName
114 ^<FFILoadDLib (name printString)>
118 handle <- self openPrim
127 ^<FFICloseHandle handle>
136 ^self call: theName args: (Array new: 0)
139 call: theName arg: theArg [
141 args <- Array new: 1.
142 args at: 1 put: theArg.
143 ^self call: theName args: args.
146 call: theName arg: argOne arg: argTwo [
148 args <- Array new: 2.
149 args at: 1 put: argOne.
150 args at: 2 put: argTwo.
151 ^self call: theName args: args.
154 call: theName arg: argOne arg: argTwo arg: argThree [
156 args <- Array new: 3.
157 args at: 1 put: argOne.
158 args at: 2 put: argTwo.
159 args at: 3 put: argThree.
160 ^self call: theName args: args.
164 ^self callInt: theName args: (Array new: 0)
167 callInt: theName arg: theArg [
169 args <- Array new: 1.
170 args at: 1 put: theArg.
171 ^self callInt: theName args: args.
174 callInt: theName arg: argOne arg: argTwo [
176 args <- Array new: 2.
177 args at: 1 put: argOne.
178 args at: 2 put: argTwo.
179 ^self callInt: theName args: args.
182 callInt: theName arg: argOne arg: argTwo arg: argThree [
184 args <- Array new: 3.
185 args at: 1 put: argOne.
186 args at: 2 put: argTwo.
187 args at: 3 put: argThree.
188 ^self callInt: theName args: args.
192 ^self callStr: theName args: (Array new: 0)
195 callStr: theName arg: theArg [
197 args <- Array new: 1.
198 args at: 1 put: theArg.
199 ^self callStr: theName args: args.
202 callStr: theName arg: argOne arg: argTwo [
204 args <- Array new: 2.
205 args at: 1 put: argOne.
206 args at: 2 put: argTwo.
207 ^self callStr: theName args: args.
210 callStr: theName arg: argOne arg: argTwo arg: argThree [
212 args <- Array new: 3.
213 args at: 1 put: argOne.
214 args at: 2 put: argTwo.
215 args at: 3 put: argThree.
216 ^self callStr: theName args: args.
219 call: theName args: theArgs [
221 func <- self at: theName.
222 args <- theArgs asArray.
223 <FFICall handle func args>
226 callInt: theName args: theArgs [
228 func <- self at: theName.
229 args <- theArgs asArray.
230 <FFICallRetInt handle func args>
233 callStr: theName args: theArgs [
235 func <- self at: theName.
236 args <- theArgs asArray.
237 <FFICallRetStr handle func args>
242 symb <- self at: theName.
243 ^<FFIGetInt handle symb>
246 setInt: theName value: anInt [
248 symb <- self at: theName.
249 <FFISetInt handle symb anInt>