fix syntax

This commit is contained in:
2026-02-17 09:12:48 -06:00
parent 6f6f987649
commit d509f7cbb8
21 changed files with 503 additions and 453 deletions

View File

@@ -56,13 +56,14 @@ JSC_CCALL(joystick_get_joysticks,
int count = 0;
SDL_JoystickID *joysticks = SDL_GetJoysticks(&count);
if (!joysticks) 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, joysticks[i]));
JS_SetPropertyNumber(js, arr, i, JS_NewUint32(js, joysticks[i]));
}
SDL_free(joysticks);
return arr;
JS_RETURN(arr);
)
// SDL_GetJoystickNameForID(id) -> string
@@ -254,10 +255,11 @@ JSC_CCALL(joystick_get_ball,
JS_ToInt32(js, &ball, argv[0]);
int dx, dy;
if (!SDL_GetJoystickBall(joystick, ball, &dx, &dy)) return JS_NULL;
JSValue result = JS_NewObject(js);
JS_FRAME(js);
JS_LOCAL(result, JS_NewObject(js));
JS_SetPropertyStr(js, result, "dx", JS_NewInt32(js, dx));
JS_SetPropertyStr(js, result, "dy", JS_NewInt32(js, dy));
return result;
JS_RETURN(result);
)
JSC_CCALL(joystick_get_hat,
@@ -311,8 +313,7 @@ JSC_CCALL(joystick_get_power_info,
SDL_Joystick *joystick = js2SDL_Joystick(js, self);
int percent;
SDL_PowerState state = SDL_GetJoystickPowerInfo(joystick, &percent);
JSValue result = JS_NewObject(js);
const char *state_str;
switch (state) {
case SDL_POWERSTATE_ON_BATTERY: state_str = "on_battery"; break;
@@ -321,9 +322,12 @@ JSC_CCALL(joystick_get_power_info,
case SDL_POWERSTATE_CHARGED: state_str = "charged"; break;
default: state_str = "unknown"; break;
}
JS_FRAME(js);
JS_LOCAL(result, JS_NewObject(js));
JS_SetPropertyStr(js, result, "state", JS_NewString(js, state_str));
JS_SetPropertyStr(js, result, "percent", JS_NewInt32(js, percent));
return result;
JS_RETURN(result);
)
JSC_CCALL(joystick_close,
@@ -381,13 +385,13 @@ static const JSCFunctionListEntry js_joystick_funcs[] = {
CELL_USE_INIT(
SDL_Init(SDL_INIT_JOYSTICK);
QJSCLASSPREP_FUNCS(SDL_Joystick);
JSValue ret = JS_NewObject(js);
JS_FRAME(js);
JS_LOCAL(ret, JS_NewObject(js));
JS_SetPropertyFunctionList(js, ret, js_joystick_funcs, countof(js_joystick_funcs));
// Export axis constants
JS_SetPropertyStr(js, ret, "AXIS_MAX", JS_NewInt32(js, SDL_JOYSTICK_AXIS_MAX));
JS_SetPropertyStr(js, ret, "AXIS_MIN", JS_NewInt32(js, SDL_JOYSTICK_AXIS_MIN));
return ret;
JS_RETURN(ret);
)