Created
September 8, 2012 11:18
-
-
Save preslavrachev/3673663 to your computer and use it in GitHub Desktop.
Executing Objective-C code from Haxe (Using NME's native extensions)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#in the Extension folder: | |
haxelib run hxcpp Build.xml -Diphoneos #device | |
#or | |
haxelib run hxcpp Build.xml -Diphonesim #simulator | |
#or | |
haxelib run hxcpp Build.xml #desktop - Mac or Windows respectively | |
#then build the Haxe project, and use XCode to compile and deploy the C++ code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- PATH: Extension/project/Build.xml--> | |
<!-- .... --> | |
!-- Find the "files" section --> | |
<files id="common"> | |
<compilerflag value="-Iinclude"/> | |
<file name="common/ExternalInterface.cpp"/> | |
<file name="common/Test.cpp"/> | |
!-- Insert the ObjCTest.mm file there --> | |
<file name="common/ObjCTest.mm"/> | |
</files> | |
<!-- .... --> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- PATH: Project/Extension Test.nmml --> | |
<!-- change the following line --> | |
<include path="../Extension" /> | |
<!-- to --> | |
<extension name="test" path="../Extension" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- PATH: Project/ExtensionTest.hx --> | |
private function construct ():Void { | |
Test.nslog(); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- PATH: Extension/project/common/ExternalInterface.cpp --> | |
#include "ObjCTest.h" | |
//.... | |
using namespace test; | |
static value test_nslog () { | |
return alloc_int (testNSLog ()); | |
} | |
DEFINE_PRIM (test_nslog, 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- PATH: Extension/project/include/ObjCTest.h--> | |
#import <hx/CFFI.h> | |
namespace test { | |
int testNSLog(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- PATH: Extension/project/common/ObjCTest.mm--> | |
<!-- NOTE: It is important to use the extension ".mm" (Objective-C++) | |
rather than ".m" (Objective-C) | |
--> | |
#import "ObjCTest.h" | |
#import <Foundation/Foundation.h> | |
namespace test { | |
int testNSLog(value str) { | |
//I know, the example is super silly, but easy enough to | |
//demonstrate the idea | |
NSString *msg = [[NSString alloc] initWithCString:"Testing..."]; | |
NSLog(msg); | |
return 0; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- PATH: Extension/Test.hx --> | |
public static function nslog (message:String):Void { | |
objc_call_nslog (message); | |
} | |
//... | |
private static var objc_call_nslog = Lib.load ("test", "test_nslog", 0); | |
// the "0" is for the number of arguments that the function accepts | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment