[NTLK] Proof of Concept: Moving data from Einstein to iOS

Jake Bordens jake at allaboutjake.com
Wed Dec 2 21:50:57 EST 2015


As suggested by Paul, I just checked in a new branch with a very early, incomplete version of a NewtonScript-to-ObjectiveC bridge for Einstein.  This makes it possible to call Objective-C code from NewtonScript inside the emulator.  I also added support for ARC and put a crudely sketched logo on the launch screen because I was tired of just white text.

The bridging code has a long way to go, but its a start.  It is based on the NSInvocation class.  Right now it only supports parameters and returns types that are object pointers, but in the future it could be made to support native types.  Even with this limitation, it is pretty useful (if long winded)  Here is an example of some NewtonScript code that calls a instance method on the application delegate:

	// Make an NSString to hold the data we want to pass to iOS
	local nsstring := call ObjCBridge.MakeNSString with (item.body.text);

	// Get the shared application by invoking on UIApplication
	local invocation := call ObjCBridge.MakeNSInvocation with ("UIApplication", "+sharedApplication");
	call ObjCBridge.Invoke with (invocation);
	local sharedApplication := call ObjCBridge.GetInvocationReturn_Object with (invocation);
	call ObjCBridge.ReleaseObject with (invocation);

	// Get the delegate by invoking on the sharedApplication
	invocation := call ObjCBridge.MakeNSInvocation with ("UIApplication", "-delegate");
	call ObjCBridge.SetInvocationTarget with (invocation, sharedApplication);
	call ObjCBridge.Invoke with (invocation);
	local appDelegate := call ObjCBridge.GetInvocationReturn_Object with (invocation);
	call ObjCBridge.ReleaseObject with (invocation);

	// Send the share message to the application delegate
	invocation := call ObjCBridge.MakeNSInvocation with ("iEinsteinAppDelegate", "-share:");
	call ObjCBridge.SetInvocationTarget with (invocation, appDelegate);
	call ObjCBridge.SetInvocationArgument_Object with (invocation, nsstring, 2);
	call ObjCBridge.Invoke with (invocation);
	call ObjCBridge.ReleaseObject with (invocation);

	// Release everything else
	call ObjCBridge.ReleaseObject with (appDelegate);
	call ObjCBridge.ReleaseObject with (sharedApplication);
	call ObjCBridge.ReleaseObject with (nsstring);


You can find it in the "ObjCBridging" branch.  I removed my old "iOS Sharing" branch because it is no longer current and is not compatible with this bridging implementation.  If we want to merge this kind of thing into the main branch, we need to check to make sure it doesn't break the Android builds.  There may be some things that need to be #ifdef'd out or something.

Maybe we can get Travis setup to do android builds as well?  This is not my area of expertise.
Jake





On 11/23/15, 3:36 PM, "newtontalk-bounces at newtontalk.net on behalf of Paul Guyot" <newtontalk-bounces at newtontalk.net on behalf of pguyot at kallisys.net> wrote:

>> Building REX from scratch is quite difficult as you need the MacOS toolchain. I have written the "mosrun" interpreter ("MacOS runtime environment") that lets you run all the Newton MPW tools on OS X (and probably any other OS, as the code is plain C++).
>> 
>> I did manage to compile the network driver module for Einstein and link it into the REX, but I was not able to build a new Rex from scratch. Paul code is missing resource forks, and I don't remember if he was able to find them in 2013 when we tried all this.
>> 
>> "https://github.com/MatthiasWM/dynee5/tree/master/Alienate"
>
>I don't remember having issues with resource forks, yet I do remember using mosrun to build a new REX not so long ago (was it in 2013 ?). But I might have forgotten.
>
>libffi definitely doesn't work on 64 bits systems : even if you could get support for iOS it is completely broken.
>https://github.com/pguyot/Einstein/commit/4eab28efa049aa946cb969969c40eb6e4ca03155
>
>However, a clean way to handle what you try to achieve would be to implement an ObjC-NewtonScript bridge for iOS and MacOS X, and this would definitely replace libffi on these platforms.
>
>Paul
>
>----------------------------------------------------------------------
>
>http://newtontalk.net/


More information about the NewtonTalk mailing list