In article <1104663710.743774.22610@[EMAIL PROTECTED]
>,
"Erik" <customimage@[EMAIL PROTECTED]
> wrote:
[...]
> Anyway,
>
> I was reading some docs on Objective-C, which I have yet to really
> start learning, and I found myself wondering on how Mops (or any OO
> Forth for that matter) would handle instantiating or calling objects in
> Objective C or C++.
>
If it's about calling Cocoa/Objective C from where ever:
<QUOTE>
Re: Calling Cocoa APIs from C?
comp.sys.mac.programmer.help
2000-29-09
Marcel Weiher wrote:
>
> Jerome Chan <eviltofu@[EMAIL PROTECTED]
> writes:
>
> >Is there a way to do this? Or to make Obj-C calls from C? I'm trying
> >to get SmallEiffel to work under OSX and Eiffel allows C calls. The
> >other option would be to use carbon. :/
>
> Yes.
>
> You need to call the C function objc_msgSend( receiver, selector,
args... ).
>
> The function sel_getUid() will get you a selector (from a C-String), and
> objc_getClass() to get a class (also from a C-String).
----------------------
</QUOTE>
from developer docs
file:///Developer/Do***entation/Cocoa/Conceptual/ObjectiveC/9objc_runtime
_reference/index.html
Translated to a non OO Forth:
\ call obj C from MacForth.
\ very simple and trivial usage, no creating instances etc.
\ see carboncocoa.pdf
anew --cocoa--
default-order
decimal
framework cocoa.framework
cocoa.framework
1 machofunc _objc_getClass ( 0string:class -- id )
1 machofunc _sel_getUid ( 0string:method -- SEL )
(*
I don't know in advance how many arguments I'm sending,
so I use an arbitrary default of 7. The first 2 for receiver
and selector and the other 5 for possible arguments.
*)
7 machofunc _objc_msgSend
( id:receiver SEL:selector arg1 ... arg5 -- ret )
\ provide stubs, the actual method will pick what it needs.
: args ( n -- 5-n_stubs )
dup 5 > abort" too many arguments!"
5 swap - 0 ?do 0 loop ;
\ these should be used before and after using the obj-c stuff!
: allocPool ( -- id )
0" NSAutoreleasePool" _objc_getClass
0" alloc" _sel_getUid
0 args _objc_msgSend
0" init" _sel_getUid
0 args _objc_msgSend ;
: releasePool ( id -- ret )
0" release" _sel_getUid
0 args _objc_msgSend ;
prior.stream
\ example:
: pp
allocpool >r \ prolog
0" NSProcessInfo" _objc_getClass \ create processInfo
0" processInfo" _sel_getUid
0 args _objc_msgSend
0" processName" _sel_getUid \ retrieve processName
0 args _objc_msgSend
0" getCString:" _sel_getUid \ copy to pad
pad dup 20 erase 1 args _objc_msgSend drop
r> releasepool drop \ epilog
;
pp
pad dup 0$len type ( expect: My Extended Kernel )


|