[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[S8ObjC] block

SwikiCodeRobot @> #testS8ObjCBlock

"Enumerate using a NSBlock"
| pool array nsBlock |
pool := (ObjCClass named: #NSAutoreleasePool in: #Foundation) newInstanceHandle.
array := (ObjCClass named: #NSMutableArray) newInstanceHandle.
Point selectors do: [:each| | nsString |
	nsString := S8ObjC current handle value: each.
	array value: #addObject value: nsString.
].
self print: '// creating nsBlock'.
[ nsBlock := S8ObjC current handle
	value: [":me" :obj :index :bool| | s description value |
		self print: #index ,$ ,index.
		s := array value: #objectAtIndex value: index.
		description := (s value: #description) value: #UTF8String.
		value := (obj value: #description) value: #UTF8String.
		description = value ifFalse: [ self error: 'Wrong value' ].
	]
	value: #(v #("$?" $@ I '^B')).
] on: Error do: [:ex|
	ex description = '_Callback is not a function' ifTrue: [
		^self error: 'Callback not implemented yet.'
	].
	self print: '// failed creation - ' ,ex toString "stream nextLine"
].
self print: '// About to enumerate'.
[ array
	value: #enumerateObjectsUsingBlock
	value: nsBlock
] on: Error do: [:ex|
  self print: 'error(val)=',ex toString stream nextLine
].