#ifndef IPHONE
#define IMPLEMENT_API
#endif
#if defined(HX_WINDOWS) || defined(HX_MACOS) || defined(HX_LINUX)
#define NEKO_COMPATIBLE
#endif
#ifndef STATIC_LINK
#define IMPLEMENT_API
#endif
#include <hx/CFFI.h>
#include "stdlib.h"
#include "portmidi.h"
#include <stdio.h>
static value pm_countdevices () {
return alloc_int (Pm_CountDevices() );
}
DEFINE_PRIM (pm_countdevices, 0);
PMEXPORT int Pm_CountDevices( void ) {
Pm_Initialize();
/* no error checking -- Pm_Initialize() does not fail */
return pm_descriptor_index;
}
<xml>
<set name="GCC_THIN_ARCHIVE" value="1" if="iphone"/>
<include name="${HXCPP}/build-tool/BuildCommon.xml"/>
<set name="mobile" value="1" if="iphone"/>
<set name="mobile" value="1" if="android"/>
<set name="mobile" value="1" if="webos"/>
<set name="mobile" value="1" if="blackberry"/>
<set name="SLIBEXT" value=".lib" if="windows"/>
<set name="SLIBEXT" value=".a" unless="windows"/>
<set name="SLIBEXT" value=".so" if="webos"/>
<files id="common">
<compilerflag value="-Iinclude/pm_common"/>
<compilerflag value="-Iinclude/porttime"/>
<file name="common/ExternalInterface.cpp"/>
</files>
<files id="pm_win">
<compilerflag value="-Iinclude/pm_win"/>
</files>
<set name="tool" value="exe" unless="iphone"/>
<set name="tool" value="static" if="iphone"/>
<set name="IOS_ARCH" value="-v7" if="HXCPP_ARMV7"/>
<set name="ndll-tool" value="dll" unless="iphone"/>
<set name="ndll-tool" value="static" if="iphone"/>
<set name="name_extra" value=".iphoneos${IOS_ARCH}" if="iphoneos"/>
<set name="name_extra" value=".iphonesim" if="iphonesim"/>
<set name="no_thirdparty_extras" value="1" if="iphone"/>
<set name="sdl_static" value="1" unless="mobile"/>
<unset name="sdl_static" if="dynamic_sdl"/>
<set name="no_thirdparty_extras" value="1" if="dynamic_sdl"/>
<set name="name_prefix" value="lib" if="iphone" />
<target id="NDLL" output="${name_prefix}test${name_extra}" tool="linker" toolid="${ndll-tool}">
<outdir name="../ndll/${BINDIR}" />
<ext value=".ndll" unless="mobile"/>
<files id="common"/>
<files id="pm_win"/>
</target>
<target id="default">
<target id="NDLL"/>
</target>
</xml>
<file name="common/portmidi.c"/>
static value pm_enumerate_inputs () {
int i;
int num_devices = Pm_CountDevices();
value v;
v = alloc_array(num_devices);
for (i = 0; i < num_devices; i++) {
const PmDeviceInfo *info = Pm_GetDeviceInfo(i);
v[i] = info->name;
}
return v;
}
DEFINE_PRIM (pm_enumerate_inputs, 0);
typedef struct _MIDIPort {
std::string name;
std::string type;
} MIDIPort;
MIDIPort *input_ports;
However, the implementation will also need a callback method from c++ to haxe. Another "how to achieve this" for me :-D
//Load the primitive to set the callback
var cpp_cb_connect = Lib.load ("MyExtension", "hyp_on_connect", 1);
//the callback
function onConnectFromCpp( arg : String ) : Void {
trace( 'arg from cpp:$arg' );
}
//set the callback
function setCallback( ) : Void {
cpp_cb_connect( onConnectFromCpp );
}
//Declare a reference to the callback
AutoGCRoot *_on_connect = 0;
extern "C"{
//Call the haxe callback from C
void hyp_on_connect( const char *socketId ) { val_call1( _on_connect -> get( ), alloc_string( socketId ) ); }
//primitive to pass the callback from haxe
static value hyp_cb_connect( value onCall ) { _on_connect = new AutoGCRoot( onCall ); return alloc_bool(true); } DEFINE_PRIM(hyp_cb_connect,1);
}
extern "C" { void hyp_on_connect( const char *socketId );
}
//when you want to call the haxe function
hyp_on_connect( "foo¨ );
value freenectnme_set_depth_cb( value array, value onCall ){ depth_array = new AutoGCRoot( array ); depth_cb = new AutoGCRoot( onCall ); return alloc_bool( true ); } DEFINE_PRIM( freenectnme_set_depth_cb, 2 );
public static function setDepthCb( array : Array<Int>, cb : Void -> Void ) { #if cpp freenectnme_set_depth_cb( array, cb ); #end }
But ideally the extension is as platform-agnostic as possible.
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.