Unfortunately its a bit more complex than a simple hello world. I've spent the past day and a bit reading about Objective-C and frankly I'm barely any the wiser. To me it seems to be a language written mostly for the benefit of the compiler but then I have been spoilt by using Livecode Script for the past few years.
The problem starts with understanding what this Objective-C command is doing and then trying to wrap the command with LCB scripts:
Code: Select all
EKEventStore *store = [[EKEventStore alloc] initWithAccessToEntityTypes:EKEntityMaskReminder];
I believe that the command initialises an instance of an EKEventStore and stores a reference to the new object in the pointer store. The command is a compound and also allocates memory for the new object. EKEntityMaskReminder is probably a constant but I am unable to confirm this.
The documentation shows an example of using a SpeechSynthesizer object. The code examples use single "methods" rather than a compound statement implying that I should create a bound allocation handler and an 'init' handler. The example then declares a local var tSynthesizer as an ObjcObject which makes sense but it passes this into a foreign handler where it is typed as type "ObjcID" .
At times the documentation gets a bit heavy on terminology for example the following note:
Note: No bridging of types will occur when passing a parameter in the non-fixed section of a variadic argument list. You must ensure the arguments you pass there are of the appropriate foreign type (e.g. CInt, CDouble).
I'm not sure that variadic argument list is ever fixed.
This note seems to require greater knowledge than I have. It would also be quite a good memory test at parties:
Note: When an ObjcId is converted to ObjcObject, the id is retained; when an ObjcObject converted to an ObjcId, the id is not retained. Conversely, when an ObjcRetainedId is converted to an ObjcObject, the object takes the +1 reference count (so does not retain); when an ObjcObject is put into an ObjcRetainedId, a +1 reference count is taken (so does retain).
So thats clear then !
So after many hours of reading here is the start of my library. I have no idea if it works or if I am even close, so feel free to get the red pen out:
Code: Select all
private foreign handler ObjC_EKEventStoreAlloc() returns objcRetainedID binds to "objC:EKEventstore.+alloc"
private handler CreateEventStore() returns ObjcObject
variable tEventStore as ObjcObject
put ObjC_EKEventStoreAlloc() into tEventStore