fix syntax
This commit is contained in:
33
sensor.c
33
sensor.c
@@ -27,13 +27,14 @@ JSC_CCALL(sensor_get_sensors,
|
||||
int count = 0;
|
||||
SDL_SensorID *sensors = SDL_GetSensors(&count);
|
||||
if (!sensors) 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_NewUint32(js, sensors[i]));
|
||||
JS_SetPropertyNumber(js, arr, i, JS_NewUint32(js, sensors[i]));
|
||||
}
|
||||
SDL_free(sensors);
|
||||
return arr;
|
||||
JS_RETURN(arr);
|
||||
)
|
||||
|
||||
// SDL_GetSensorNameForID(id) -> string
|
||||
@@ -95,21 +96,22 @@ JSC_CCALL(sensor_get_data,
|
||||
SDL_Sensor *sensor = js2SDL_Sensor(js, self);
|
||||
int num_values = 3;
|
||||
if (argc > 0) JS_ToInt32(js, &num_values, argv[0]);
|
||||
|
||||
|
||||
float *data = malloc(num_values * sizeof(float));
|
||||
if (!data) return JS_ThrowOutOfMemory(js);
|
||||
|
||||
|
||||
if (!SDL_GetSensorData(sensor, data, num_values)) {
|
||||
free(data);
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
JSValue arr = JS_NewArray(js);
|
||||
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(arr, JS_NewArray(js));
|
||||
for (int i = 0; i < num_values; i++) {
|
||||
JS_SetPropertyUint32(js, arr, i, JS_NewFloat64(js, data[i]));
|
||||
JS_SetPropertyNumber(js, arr, i, JS_NewFloat64(js, data[i]));
|
||||
}
|
||||
free(data);
|
||||
return arr;
|
||||
JS_RETURN(arr);
|
||||
)
|
||||
|
||||
JSC_CCALL(sensor_close,
|
||||
@@ -145,12 +147,11 @@ static const JSCFunctionListEntry js_sensor_funcs[] = {
|
||||
CELL_USE_INIT(
|
||||
SDL_Init(SDL_INIT_SENSOR);
|
||||
QJSCLASSPREP_FUNCS(SDL_Sensor);
|
||||
|
||||
JSValue ret = JS_NewObject(js);
|
||||
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(ret, JS_NewObject(js));
|
||||
JS_SetPropertyFunctionList(js, ret, js_sensor_funcs, countof(js_sensor_funcs));
|
||||
|
||||
// Export standard gravity constant
|
||||
JS_SetPropertyStr(js, ret, "STANDARD_GRAVITY", JS_NewFloat64(js, SDL_STANDARD_GRAVITY));
|
||||
|
||||
return ret;
|
||||
|
||||
JS_RETURN(ret);
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user