-
Notifications
You must be signed in to change notification settings - Fork 2
/
Nuklear.cs
66 lines (59 loc) · 1.82 KB
/
Nuklear.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using NativeLibraryLoader;
using System.Runtime.InteropServices;
namespace NuklearSharp
{
public static unsafe partial class NuklearNative
{
private static readonly NativeLibrary nk_nklib = LoadNk();
private static NativeLibrary LoadNk()
{
string[] names;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
names = new[] { "Nuklear.dll" };
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
names = new[] {
"libnuklear.so",
"libnuklear.so.4",
"libnuklear.so.4.00",
"libnuklear.so.4.00.2",
"libnuklear.so.4.0",
"libnuklear.so.4.0.2"
};
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
names = new[] { "libnuklear.dylib" };
} else {
names = new[] { "Nuklear.dll" };
}
return new NativeLibrary(names);
}
private static T LoadFunction<T>(string name)
{
return nk_nklib.LoadFunction<T>(name);
}
private static T LFT<T>()
{
var s = typeof(T).Name;
if (s.EndsWith("_t", StringComparison.Ordinal) && !s.Contains(".")) {
return LoadFunction<T>(s.Substring(0, s.Length - 2));
} else {
throw new ArgumentException("<T> passed to LFT<T> (which is LoadFunction<T> shorthand) must be like some_fun_t (=> which yields name: some_fun) and not the given '" + s + "'");
}
}
/*
* nk_char -> *signed* char (which we misinterpret as (unsigned) byte -- so sue me! it's a damn string element!!!)
* nk_uchar -> unsigned char
* nk_byte -> unsigned char
* nk_short -> signed short
* nk_ushort -> unsigned short
* nk_int -> signed int
* nk_uint -> unsigned int
* nk_size -> unsigned long (!!! IntPtr)
* nk_ptr -> unsigned long (!!! IntPtr)
*
* nk_hash -> uint
* nk_flags -> uint
* nk_rune -> uint
*/
}
}