LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.
I have just written some LCB code that crashes Livecode. I needed to convert a string into an NSString object but for some reason I initially did not spot the built in conversion.
-- Need to be able to create an NSString object
private foreign handler ObjC_NSStringAlloc() \
returns objcRetainedID \
binds to "objc:NSString.+alloc"
private foreign handler ObjC_NSStringInitWithString(in pObj as ObjcID, in pString as String) \
returns objcID \
binds to "objc:NSString.-initWithString:"
Crashed every time. Is it because I was attempting to pass a native string to the Objective-C compiler thingy?
When I think about it LCB almost had to provide a conversion routine to convert string to NSString as without it there would not be any way to pass strings in foreign handlers.
Notice the use of ObjcRetainedId.
Noticed but not understood. I thought I read that the +alloc should return an objcID and the -init should be passed the objcID and return a ObjcRetainedID. Or may be it was the other way round. Something to do with preventing an attempt to deallocate an object that has already been deallocated.
The bottom line is that it would be good if LCMark or Ali could publish some instructions, aimed at three year olds, that I could follow.
So reading the comments an object occupies some memory and that area of memory/object has a reference count associated. When the reference count drops to zero the object is destroyed.
What is unclear, to me, is what LCB does . For example an init method increments the reference count. But the LCB documents describe ObjcID as "- an id with no implicit action on its reference count" . So does this mean that the reference count does not get incremented as this is the implied action of the init method?
ObjcRetainedID is described as "an id which is expected to already have been retained. (i.e. the caller or callee expects to receive it with +1 ref count)" . So does this mean that ObjcRetainedID should be used with every init?