Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth Mac > Re: Question on...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 6 Topic 91 of 159
Post > Topic >>

Re: Question on Forth & C++/ObjC objects

by Roelf Toxopeus <these3rt0only@[EMAIL PROTECTED] > Jan 2, 2005 at 02:25 PM

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 )
 




 6 Posts in Topic:
Question on Forth & C++/ObjC objects
"Erik" <cust  2005-01-02 03:01:50 
Re: Question on Forth & C++/ObjC objects
Mike Hore <mikehoreREM  2005-01-02 21:03:01 
Re: Question on Forth & C++/ObjC objects
Roelf Toxopeus <these3  2005-01-02 14:25:10 
Re: Question on Forth & C++/ObjC objects
"Erik" <cust  2005-01-04 15:50:23 
Re: Question on Forth & C++/ObjC objects
"Erik" <cust  2005-01-04 15:56:09 
Re: Question on Forth & C++/ObjC objects
n_sacra@[EMAIL PROTECTED]  2005-01-06 03:46:46 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 16:49:46 CDT 2008.