fix syntax
This commit is contained in:
25
touch.c
25
touch.c
@@ -6,13 +6,14 @@ JSC_CCALL(touch_get_devices,
|
||||
int count = 0;
|
||||
SDL_TouchID *devices = SDL_GetTouchDevices(&count);
|
||||
if (!devices) return JS_NewArray(js);
|
||||
|
||||
JSValue arr = JS_NewArray(js);
|
||||
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(arr, JS_NewArray(js));
|
||||
for (int i = 0; i < count; i++) {
|
||||
JS_SetPropertyUint32(js, arr, i, JS_NewInt64(js, devices[i]));
|
||||
JS_SetPropertyNumber(js, arr, i, JS_NewInt64(js, devices[i]));
|
||||
}
|
||||
SDL_free(devices);
|
||||
return arr;
|
||||
JS_RETURN(arr);
|
||||
)
|
||||
|
||||
// SDL_GetTouchDeviceName(touchID) -> string
|
||||
@@ -44,23 +45,27 @@ JSC_CCALL(touch_get_device_type,
|
||||
JSC_CCALL(touch_get_fingers,
|
||||
int64_t touchID;
|
||||
JS_ToInt64(js, &touchID, argv[0]);
|
||||
|
||||
|
||||
int count = 0;
|
||||
SDL_Finger **fingers = SDL_GetTouchFingers((SDL_TouchID)touchID, &count);
|
||||
if (!fingers) return JS_NewArray(js);
|
||||
|
||||
JSValue arr = JS_NewArray(js);
|
||||
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(arr, JS_NewArray(js));
|
||||
JSValue finger = JS_NULL;
|
||||
JSLocalRef finger__lr = {.ptr = &finger};
|
||||
JS_PushLocalRef(_js_ctx, &finger__lr);
|
||||
for (int i = 0; i < count; i++) {
|
||||
SDL_Finger *f = fingers[i];
|
||||
JSValue finger = JS_NewObject(js);
|
||||
finger = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js, finger, "id", JS_NewInt64(js, f->id));
|
||||
JS_SetPropertyStr(js, finger, "x", JS_NewFloat64(js, f->x));
|
||||
JS_SetPropertyStr(js, finger, "y", JS_NewFloat64(js, f->y));
|
||||
JS_SetPropertyStr(js, finger, "pressure", JS_NewFloat64(js, f->pressure));
|
||||
JS_SetPropertyUint32(js, arr, i, finger);
|
||||
JS_SetPropertyNumber(js, arr, i, finger);
|
||||
}
|
||||
SDL_free(fingers);
|
||||
return arr;
|
||||
JS_RETURN(arr);
|
||||
)
|
||||
|
||||
static const JSCFunctionListEntry js_touch_funcs[] = {
|
||||
|
||||
Reference in New Issue
Block a user