Skip to content

Commit 87ee719

Browse files
committedSep 13, 2015
initial checkin
0 parents  commit 87ee719

13 files changed

+195
-0
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cpp/
2+
tmp/

‎.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "lib/enet"]
2+
path = lib/enet
3+
url = https://github.com/native-toolkit/enet.git

‎LICENSE.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Sven Bergström
4+
Copyright (c) 2015 snõwkit contributors
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+

‎README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# linc/enet
2+
Linc-powered wrapper for Enet (http://enet.bespin.org).
3+
4+
For more information, see the [linc homepage](http://snowkit.github.io/linc/)

‎enet/Empty.hx

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package soloud;
2+
3+
@:keep
4+
@:include('linc_empty.h')
5+
@:build(linc.Linc.touch())
6+
@:build(linc.Linc.xml('empty'))
7+
extern class Empty {
8+
9+
//external native function definition
10+
//can be wrapped in linc::libname or call directly
11+
//and the header for the lib included in linc_empty.h
12+
13+
// @:native('linc::empty::native_example')
14+
// static function native_example() : Int;
15+
16+
//inline functions can be used as wrappers
17+
18+
// static inline function example() : Void {
19+
// trace('empty project example');
20+
// }
21+
22+
} //Empty

‎lib/.keep

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.keep

‎lib/enet

Submodule enet added at 699aa7e

‎linc/Linc.hx

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package linc;
2+
3+
import haxe.io.Path;
4+
import haxe.macro.Expr;
5+
import haxe.macro.Context;
6+
7+
using haxe.macro.PositionTools;
8+
9+
10+
class Linc {
11+
12+
/** Adds a private internal inline static variable called __touch,
13+
which sets the value to the current time so that builds are always
14+
updated by the code, and native changes are dragged in automatically (except for header only changes) */
15+
macro public static function touch() : Array<Field> {
16+
17+
var _fields = Context.getBuildFields();
18+
19+
_fields.push({
20+
name: '__touch', pos: Context.currentPos(),
21+
doc: null, meta: [], access: [APrivate, AStatic, AInline],
22+
kind: FVar(macro : String, macro $v{ Std.string(Date.now().getTime()) }),
23+
});
24+
25+
return _fields;
26+
27+
} //touch
28+
29+
/** Adds a @:buildXml meta node with a linc <set> and an <import> tag.
30+
The set is named LINC_${_lib}_PATH, and points to the root folder of the library.
31+
That path is calculated from the calling file using the optional _relative_root, default ../
32+
This means that somelib/ is the root.
33+
somelib/somelib/Somelib.hx is the calling file.
34+
LINC_SOMELIB_PATH is set to somelib/
35+
${LINC_SOMELIB_PATH}/linc/linc_${_lib}.xml is added directly. */
36+
macro public static function xml(_lib:String, _relative_root:String='../'):Array<Field> {
37+
38+
var _pos = Context.currentPos();
39+
var _pos_info = _pos.getInfos();
40+
var _class = Context.getLocalClass();
41+
42+
var _source_path = Path.directory(_pos_info.file);
43+
if( !Path.isAbsolute(_source_path) ) {
44+
_source_path = Path.join([Sys.getCwd(), _source_path]);
45+
}
46+
47+
_source_path = Path.normalize(_source_path);
48+
49+
var _linc_lib_path = Path.normalize(Path.join([_source_path, _relative_root]));
50+
var _linc_include_path = Path.normalize(Path.join([ _linc_lib_path, './linc/linc_${_lib}.xml' ]));
51+
var _linc_lib_var = 'LINC_${_lib.toUpperCase()}_PATH';
52+
53+
var _define = '<set name="$_linc_lib_var" value="$_linc_lib_path/"/>';
54+
var _import_path = '$${$_linc_lib_var}linc/linc_${_lib}.xml';
55+
var _import = '<include name="$_import_path" />';
56+
57+
_class.get().meta.add(":buildXml", [{ expr:EConst( CString( '$_define\n$_import' ) ), pos:_pos }], _pos );
58+
59+
return Context.getBuildFields();
60+
61+
} //xml
62+
63+
} //Linc

‎linc/linc_enet.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "./linc_enet.h"
2+
3+
#include <hxcpp.h>
4+
5+
namespace linc {
6+
7+
namespace enet {
8+
9+
} //enet namespace
10+
11+
} //linc

‎linc/linc_enet.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef _LINC_ENET_H_
2+
#define _LINC_ENET_H_
3+
4+
#include "enet/enet.h"
5+
6+
#include <hxcpp.h>
7+
8+
namespace linc {
9+
10+
namespace enet {
11+
12+
} //enet namespace
13+
14+
} //linc
15+
16+
#endif //_LINC_ENET_H_

‎linc/linc_enet.xml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<xml>
2+
3+
<set name="NATIVE_TOOLKIT_PATH" value="${LINC_ENET_PATH}/lib/" />
4+
<include name="${LINC_OGG_PATH}/lib/enet/files.xml"/>
5+
6+
<files id='haxe'>
7+
8+
<compilerflag value='-I${LINC_ENET_PATH}/lib/'/>
9+
<compilerflag value='-I${LINC_ENET_PATH}/linc/'/>
10+
11+
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/enet/include/"/>
12+
13+
<include name="${LINC_OGG_PATH}/lib/enet/defines.xml"/>
14+
15+
<file name='${LINC_OGG_PATH}/linc/linc_enet.cpp' />
16+
</files>
17+
18+
<target id="haxe">
19+
20+
<files id="native-toolkit-enet"/>
21+
22+
</target>
23+
24+
</xml>

‎test/Test.hx

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
class Test {
3+
4+
static function main() {
5+
6+
}
7+
8+
}

‎test/build.hxml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-main Test.hx
2+
-cpp cpp/
3+
-cp ../
4+
# pick a target
5+
6+
#-D mac
7+
#-D windows
8+
#-D linux
9+
10+
# To build 32 or 64 bit
11+
#(if not using the default for your platform):
12+
13+
#-D HXCPP_M64
14+
#-D HXCPP_M32
15+
16+
#-cmd ./cpp/Test
17+
#-cmd ./cpp/Test.exe

0 commit comments

Comments
 (0)
Please sign in to comment.