Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!dewey.soe.berkeley.edu!oster From: oster@dewey.soe.berkeley.edu (David Phillip Oster) Newsgroups: comp.sys.mac.programmer Subject: Re: Calling Code resources? Message-ID: <28734@ucbvax.BERKELEY.EDU> Date: 8 Apr 89 12:01:22 GMT References: <11817@ut-emx.UUCP> <6917@hoptoad.uucp> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster) Distribution: usa Organization: School of Education, UC-Berkeley Lines: 66 In article <6917@hoptoad.uucp> tim@hoptoad.UUCP (Tim Maroney) writes: >In article <11817@ut-emx.UUCP> newman@ut-emx.UUCP (David Newman) writes: >>how do you call a code resource from another piece of code? Can it be >>done from a high-level language? How might it be done in Pascal? >In Pascal, you're probably going to need to link in some assembly >language or at least include some INLINEs. Lightspeed Pascal can call other pascal functions two ways: 1.) Pascal allows the parameter of a function to be a procedure, something like: PROCEDURE foo( PROCEDURE a( Integer : b)); BEGIN a(3); END; Check your manuals for the exact syntax. If you call foo(POINTER(GetResource('MDEF', 128)^)); the POINTER() will cast the result of the GetResource()^ to a gerneric pointer that it is legal to pass to anything. Once again, watch your locking, code must be loced before you call it. >Lightspeed C, seems to have some problems with >casting things to function pointers (actually, K&R seems ambiguous on >the proper syntax, so I guess we can't blame them): I've never had any trouble casting things to function pointer in lightspeed C. But then, I always use typedefs to keep things simple enough that I can follow them. Examples: typedef void (*SubrPtr)(); typedef short (*FuncPtr)(); typedef long (*LFuncPtr)(); void CallC(f, arg)SubPtr f;Integer arg;{ (*f)(arg); } The expression ((SubrPtr) *GetResource('CDEF', 128)) is much easier to understand than (((*void)()) *GetResource('CDEF', 128)). But that only covers calling procedures that use the C calling sequence. If you are calling a function that uses the pascal calling sequence, such as a MDEF, a WDEF, or a CDEF, you can use the routines defined in teh Lightspeed C file Note, these functions are not documented in the new LightSpeed C manual. The function pointer goes _after_ all the arguments: CallPascalL(varCode, win, mesg, param, *GetResource('WDEF', 128)); for example. Once again, make sure the code resource is locked before you call it. Lightspeed Pascal probably also implements these CallPascal() functions. I don't know if Lightspeed Pascal includes a set of CallC() functions, but I'd be surprised. ------ To Tim Maroney: great pair of postings about ListManager and the usenet community. --- David Phillip Oster --"No doubt about it, time to get Arpa: oster@dewey.soe.berkeley.edu --a new signature" Uucp: {uwvax,decvax}!ucbvax!oster%dewey.soe.berkeley.edu