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

test[jscocoa] 001 C and ObjC calls

Code

"ObjectiveC class resolution & calls"
| numBundles nsBundle |
nsBundle := Smalltalk jsObjectAt: #NSBundle.
numBundles := nsBundle#allBundles#count.
numBundles < 1 ifTrue: [ self error: 'no bundles found' ].
self print: 'numBundles=',numBundles.
Smalltalk gc.


"ObjectiveC function resolution & call"
self print: 'NSUserName()=',# #NSUserName.
self print: 'NSFullUserName()=',# #NSFullUserName.
self print: 'NSHomeDirectory()=',# #NSHomeDirectory.
self print: 'NSHomeDirectoryForUser()=',# #NSHomeDirectoryForUser.
self print: 'NSTemporaryDirectory()=',# #NSTemporaryDirectory.
Smalltalk gc.


"ObjectiveC constant resolution"
| value aName |
aName := #NSBundleDidLoadNotification.
value := Smalltalk jsObjectAt: aName ifAbsent: [].
value isNil ifTrue: [ self error: 'Missing Constant ' ,aName ].
self print: aName ,'=' ,value.
Smalltalk gc.


"External(C) functions resolution & evaluation"
| value |
value := # #CFAbsoluteTimeGetCurrent.
value isNumber ifFalse: [ self error: #mustBeNumber ].
self print: 'Result=',value.
Smalltalk gc.


"External(C) constants resolution"
| value aName |
aName := #CFAbsoluteTimeGetCurrent.
value := Smalltalk jsObjectAt: aName ifAbsent: [].
value isNil ifTrue: [ self error: 'Missing Constant ' ,aName ].
self print: aName ,'=' ,value.
Smalltalk gc.


References

IMPORTANT
Ensure that you have defined the required constants and functions for testing in the ".bridgesupport" file.
 self cancelFileIn"
 the following definitions are samples to edit
 your default.bridgetsupport file"!


    <!- required for testing >
    <function name='NSUserName'> <retval type='@' /> </function>
    <function name='NSFullUserName'> <retval type='@' /> </function>
    <function name='NSHomeDirectory'> <retval type='@' /> </function>
    <function name='NSHomeDirectoryForUser'> <retval type='@' /> </function>
    <function name='NSTemporaryDirectory'> <retval type='@' /> </function>
    <function name='CFAbsoluteTimeGetCurrent'> <retval type='d' /> </function>
    <constant name='NSBundleDidLoadNotification' declared_type='NSString*' type='^{__CFString=}' const='true'/>