Skip to content

Commit 493ee98

Browse files
committed
Initial implementation of ALC.getStringList()
1 parent e947771 commit 493ee98

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

project/src/media/openal/OpenALBindings.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3398,6 +3398,73 @@ namespace lime {
33983398
}
33993399

34003400

3401+
value lime_alc_get_string_list (value device, int param) {
3402+
3403+
ALCdevice* alcDevice = (ALCdevice*)val_data (device);
3404+
const char* result = alcGetString (alcDevice, param);
3405+
3406+
if (!result || *result == '\0') {
3407+
3408+
return alloc_null ();
3409+
3410+
}
3411+
3412+
value list = alloc_array (0);
3413+
3414+
while (*result != '\0') {
3415+
3416+
val_array_push (list, alloc_string (result));
3417+
result += strlen (result) + 1;
3418+
3419+
}
3420+
3421+
return list;
3422+
3423+
}
3424+
3425+
3426+
HL_PRIM varray* HL_NAME(hl_alc_get_string_list) (HL_CFFIPointer* device, int param) {
3427+
3428+
ALCdevice* alcDevice = device ? (ALCdevice*)device->ptr : 0;
3429+
const char* result = alcGetString(alcDevice, param);
3430+
3431+
if (!result || *result == '\0') {
3432+
3433+
return 0;
3434+
3435+
}
3436+
3437+
int length = 0;
3438+
3439+
const char* temp = result;
3440+
while (*temp != '\0') {
3441+
3442+
length++;
3443+
temp += strlen (temp) + 1;
3444+
3445+
}
3446+
3447+
varray* list = hl_alloc_array (&hlt_bytes, length);
3448+
vbyte** listData = hl_aptr (list, vbyte*);
3449+
3450+
while (*result != '\0') {
3451+
3452+
int length = strlen (result);
3453+
char* _result = (char*)malloc (length + 1);
3454+
strcpy (_result, result);
3455+
3456+
*listData = (vbyte*)_result;
3457+
listData++;
3458+
3459+
result += strlen (result) + 1;
3460+
3461+
}
3462+
3463+
return list;
3464+
3465+
}
3466+
3467+
34013468
bool lime_alc_make_context_current (value context) {
34023469

34033470
ALCcontext* alcContext = (ALCcontext*)val_data (context);
@@ -3622,6 +3689,7 @@ namespace lime {
36223689
DEFINE_PRIME1 (lime_alc_get_error);
36233690
DEFINE_PRIME3 (lime_alc_get_integerv);
36243691
DEFINE_PRIME2 (lime_alc_get_string);
3692+
DEFINE_PRIME2 (lime_alc_get_string_list);
36253693
DEFINE_PRIME1 (lime_alc_make_context_current);
36263694
DEFINE_PRIME1 (lime_alc_open_device);
36273695
DEFINE_PRIME1v (lime_alc_pause_device);
@@ -3746,6 +3814,7 @@ namespace lime {
37463814
DEFINE_HL_PRIM (_I32, hl_alc_get_error, _TCFFIPOINTER);
37473815
DEFINE_HL_PRIM (_ARR, hl_alc_get_integerv, _TCFFIPOINTER _I32 _I32);
37483816
DEFINE_HL_PRIM (_BYTES, hl_alc_get_string, _TCFFIPOINTER _I32);
3817+
DEFINE_HL_PRIM (_ARR, hl_alc_get_string_list, _TCFFIPOINTER _I32);
37493818
DEFINE_HL_PRIM (_BOOL, hl_alc_make_context_current, _TCFFIPOINTER);
37503819
DEFINE_HL_PRIM (_TCFFIPOINTER, hl_alc_open_device, _STRING);
37513820
DEFINE_HL_PRIM (_VOID, hl_alc_pause_device, _TCFFIPOINTER);

src/lime/_internal/backend/native/NativeCFFI.hx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,8 @@ class NativeCFFI
16831683

16841684
@:cffi private static function lime_alc_get_string(device:CFFIPointer, param:Int):Dynamic;
16851685

1686+
@:cffi private static function lime_alc_get_string_list(device:CFFIPointer, param:Int):Array<Dynamic>;
1687+
16861688
@:cffi private static function lime_alc_make_context_current(context:CFFIPointer):Bool;
16871689

16881690
@:cffi private static function lime_alc_open_device(devicename:String):CFFIPointer;
@@ -1853,6 +1855,7 @@ class NativeCFFI
18531855
private static var lime_alc_get_integerv = new cpp.Callable<cpp.Object->Int->Int->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_alc_get_integerv",
18541856
"oiio", false));
18551857
private static var lime_alc_get_string = new cpp.Callable<cpp.Object->Int->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_alc_get_string", "oio", false));
1858+
private static var lime_alc_get_string_list = new cpp.Callable<cpp.Object->Int->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_alc_get_string_list", "oio", false));
18561859
private static var lime_alc_make_context_current = new cpp.Callable<cpp.Object->Bool>(cpp.Prime._loadPrime("lime", "lime_alc_make_context_current", "ob",
18571860
false));
18581861
private static var lime_alc_open_device = new cpp.Callable<String->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_alc_open_device", "so", false));
@@ -1976,6 +1979,7 @@ class NativeCFFI
19761979
private static var lime_alc_get_error = CFFI.load("lime", "lime_alc_get_error", 1);
19771980
private static var lime_alc_get_integerv = CFFI.load("lime", "lime_alc_get_integerv", 3);
19781981
private static var lime_alc_get_string = CFFI.load("lime", "lime_alc_get_string", 2);
1982+
private static var lime_alc_get_string_list = CFFI.load("lime", "lime_alc_get_string_list", 2);
19791983
private static var lime_alc_make_context_current = CFFI.load("lime", "lime_alc_make_context_current", 1);
19801984
private static var lime_alc_open_device = CFFI.load("lime", "lime_alc_open_device", 1);
19811985
private static var lime_alc_pause_device = CFFI.load("lime", "lime_alc_pause_device", 1);
@@ -2320,6 +2324,11 @@ class NativeCFFI
23202324
return null;
23212325
}
23222326

2327+
@:hlNative("lime", "hl_alc_get_string_list") private static function lime_alc_get_string_list(device:CFFIPointer, param:Int):hl.NativeArray<hl.Bytes>
2328+
{
2329+
return null;
2330+
}
2331+
23232332
@:hlNative("lime", "hl_alc_make_context_current") private static function lime_alc_make_context_current(context:ALContext):Bool
23242333
{
23252334
return false;

src/lime/media/openal/ALC.hx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,31 @@ class ALC
152152
#end
153153
}
154154

155+
public static function getStringList(device:ALDevice, param:Int):Array<String>
156+
{
157+
#if (lime_cffi && lime_openal && !macro)
158+
if (param == DEVICE_SPECIFIER ||
159+
param == ALL_DEVICES_SPECIFIER)
160+
{
161+
var result = NativeCFFI.lime_alc_get_string_list(device, param);
162+
#if hl
163+
if (result == null) return [];
164+
var _result = [];
165+
for (i in 0...result.length)
166+
_result[i] = CFFI.stringValue(result[i]);
167+
return _result;
168+
#else
169+
return result;
170+
#end
171+
172+
}
173+
174+
return [getString(device, param)];
175+
#else
176+
return null;
177+
#end
178+
}
179+
155180
public static function makeContextCurrent(context:ALContext):Bool
156181
{
157182
#if (lime_cffi && lime_openal && !macro)

0 commit comments

Comments
 (0)