fix scheduler
This commit is contained in:
@@ -20,7 +20,7 @@ JSC_CCALL(display_setRefreshRate,
|
||||
if (!pd_display) return JS_ThrowInternalError(js, "display not initialized");
|
||||
float rate = (float)js2number(js, argv[0]);
|
||||
pd_display->setRefreshRate(rate);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(display_getRefreshRate,
|
||||
@@ -37,14 +37,14 @@ JSC_CCALL(display_setInverted,
|
||||
if (!pd_display) return JS_ThrowInternalError(js, "display not initialized");
|
||||
int flag = JS_ToBool(js, argv[0]);
|
||||
pd_display->setInverted(flag);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(display_setScale,
|
||||
if (!pd_display) return JS_ThrowInternalError(js, "display not initialized");
|
||||
unsigned int scale = (unsigned int)js2number(js, argv[0]);
|
||||
pd_display->setScale(scale);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(display_setMosaic,
|
||||
@@ -52,7 +52,7 @@ JSC_CCALL(display_setMosaic,
|
||||
unsigned int x = (unsigned int)js2number(js, argv[0]);
|
||||
unsigned int y = (unsigned int)js2number(js, argv[1]);
|
||||
pd_display->setMosaic(x, y);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(display_setFlipped,
|
||||
@@ -60,7 +60,7 @@ JSC_CCALL(display_setFlipped,
|
||||
int x = JS_ToBool(js, argv[0]);
|
||||
int y = JS_ToBool(js, argv[1]);
|
||||
pd_display->setFlipped(x, y);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(display_setOffset,
|
||||
@@ -68,7 +68,7 @@ JSC_CCALL(display_setOffset,
|
||||
int x = (int)js2number(js, argv[0]);
|
||||
int y = (int)js2number(js, argv[1]);
|
||||
pd_display->setOffset(x, y);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
static const JSCFunctionListEntry js_display_funcs[] = {
|
||||
|
||||
@@ -30,14 +30,14 @@ JSC_CCALL(gfx_clear,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
LCDColor color = (LCDColor)js2number(js, argv[0]);
|
||||
pd_gfx->clear(color);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setBackgroundColor,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
LCDSolidColor color = (LCDSolidColor)(int)js2number(js, argv[0]);
|
||||
pd_gfx->setBackgroundColor(color);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setDrawMode,
|
||||
@@ -50,38 +50,38 @@ JSC_CCALL(gfx_setDrawMode,
|
||||
JSC_CCALL(gfx_setDrawOffset,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
pd_gfx->setDrawOffset((int)js2number(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setClipRect,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
pd_gfx->setClipRect((int)js2number(js, argv[0]), (int)js2number(js, argv[1]),
|
||||
(int)js2number(js, argv[2]), (int)js2number(js, argv[3]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_clearClipRect,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
pd_gfx->clearClipRect();
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setLineCapStyle,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
pd_gfx->setLineCapStyle((LCDLineCapStyle)(int)js2number(js, argv[0]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setFont,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
pd_gfx->setFont(js2font(js, argv[0]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setTextTracking,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
pd_gfx->setTextTracking((int)js2number(js, argv[0]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_getTextTracking,
|
||||
@@ -92,13 +92,13 @@ JSC_CCALL(gfx_getTextTracking,
|
||||
JSC_CCALL(gfx_pushContext,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
pd_gfx->pushContext(argc > 0 ? js2bitmap(js, argv[0]) : NULL);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_popContext,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
pd_gfx->popContext();
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
// --- Drawing Primitives ---
|
||||
@@ -109,7 +109,7 @@ JSC_CCALL(gfx_drawBitmap,
|
||||
if (!bmp) return JS_ThrowTypeError(js, "invalid bitmap");
|
||||
pd_gfx->drawBitmap(bmp, (int)js2number(js, argv[1]), (int)js2number(js, argv[2]),
|
||||
argc > 3 ? (LCDBitmapFlip)(int)js2number(js, argv[3]) : kBitmapUnflipped);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_drawLine,
|
||||
@@ -117,7 +117,7 @@ JSC_CCALL(gfx_drawLine,
|
||||
pd_gfx->drawLine((int)js2number(js, argv[0]), (int)js2number(js, argv[1]),
|
||||
(int)js2number(js, argv[2]), (int)js2number(js, argv[3]),
|
||||
(int)js2number(js, argv[4]), (LCDColor)js2number(js, argv[5]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_drawRect,
|
||||
@@ -125,7 +125,7 @@ JSC_CCALL(gfx_drawRect,
|
||||
pd_gfx->drawRect((int)js2number(js, argv[0]), (int)js2number(js, argv[1]),
|
||||
(int)js2number(js, argv[2]), (int)js2number(js, argv[3]),
|
||||
(LCDColor)js2number(js, argv[4]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_fillRect,
|
||||
@@ -133,7 +133,7 @@ JSC_CCALL(gfx_fillRect,
|
||||
pd_gfx->fillRect((int)js2number(js, argv[0]), (int)js2number(js, argv[1]),
|
||||
(int)js2number(js, argv[2]), (int)js2number(js, argv[3]),
|
||||
(LCDColor)js2number(js, argv[4]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_fillTriangle,
|
||||
@@ -142,7 +142,7 @@ JSC_CCALL(gfx_fillTriangle,
|
||||
(int)js2number(js, argv[2]), (int)js2number(js, argv[3]),
|
||||
(int)js2number(js, argv[4]), (int)js2number(js, argv[5]),
|
||||
(LCDColor)js2number(js, argv[6]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_drawEllipse,
|
||||
@@ -151,7 +151,7 @@ JSC_CCALL(gfx_drawEllipse,
|
||||
(int)js2number(js, argv[2]), (int)js2number(js, argv[3]),
|
||||
(int)js2number(js, argv[4]), (float)js2number(js, argv[5]),
|
||||
(float)js2number(js, argv[6]), (LCDColor)js2number(js, argv[7]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_fillEllipse,
|
||||
@@ -160,7 +160,7 @@ JSC_CCALL(gfx_fillEllipse,
|
||||
(int)js2number(js, argv[2]), (int)js2number(js, argv[3]),
|
||||
(float)js2number(js, argv[4]), (float)js2number(js, argv[5]),
|
||||
(LCDColor)js2number(js, argv[6]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_SCALL(gfx_drawText,
|
||||
@@ -176,7 +176,7 @@ JSC_CCALL(gfx_drawScaledBitmap,
|
||||
if (!bmp) return JS_ThrowTypeError(js, "invalid bitmap");
|
||||
pd_gfx->drawScaledBitmap(bmp, (int)js2number(js, argv[1]), (int)js2number(js, argv[2]),
|
||||
(float)js2number(js, argv[3]), (float)js2number(js, argv[4]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_drawRotatedBitmap,
|
||||
@@ -187,14 +187,14 @@ JSC_CCALL(gfx_drawRotatedBitmap,
|
||||
(float)js2number(js, argv[3]), (float)js2number(js, argv[4]),
|
||||
(float)js2number(js, argv[5]), (float)js2number(js, argv[6]),
|
||||
(float)js2number(js, argv[7]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setPixel,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
pd_gfx->setPixel((int)js2number(js, argv[0]), (int)js2number(js, argv[1]),
|
||||
(LCDColor)js2number(js, argv[2]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
// --- Bitmap Functions ---
|
||||
@@ -211,7 +211,7 @@ JSC_CCALL(gfx_freeBitmap,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
LCDBitmap *bmp = js2bitmap(js, argv[0]);
|
||||
if (bmp) pd_gfx->freeBitmap(bmp);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_SCALL(gfx_loadBitmap,
|
||||
@@ -235,7 +235,7 @@ JSC_CCALL(gfx_clearBitmap,
|
||||
LCDBitmap *bmp = js2bitmap(js, argv[0]);
|
||||
if (!bmp) return JS_ThrowTypeError(js, "invalid bitmap");
|
||||
pd_gfx->clearBitmap(bmp, argc > 1 ? (LCDColor)js2number(js, argv[1]) : kColorWhite);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_getBitmapData,
|
||||
@@ -279,13 +279,13 @@ JSC_SCALL(gfx_getTextWidth,
|
||||
JSC_CCALL(gfx_display,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
pd_gfx->display();
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_markUpdatedRows,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
pd_gfx->markUpdatedRows((int)js2number(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_copyFrameBufferBitmap,
|
||||
|
||||
@@ -57,10 +57,10 @@ static void json_decode_table_value(json_decoder *decoder, const char *key, json
|
||||
if (ctx->stack_depth > 1) {
|
||||
jsval = ctx->stack[ctx->stack_depth - 1];
|
||||
} else {
|
||||
jsval = JS_UNDEFINED;
|
||||
jsval = JS_NULL;
|
||||
}
|
||||
break;
|
||||
default: jsval = JS_UNDEFINED; break;
|
||||
default: jsval = JS_NULL; break;
|
||||
}
|
||||
JS_SetPropertyStr(ctx->js, container, key, jsval);
|
||||
}
|
||||
@@ -77,7 +77,7 @@ static void json_decode_array_value(json_decoder *decoder, int pos, json_value v
|
||||
case kJSONInteger: jsval = JS_NewInt32(ctx->js, value.data.intval); break;
|
||||
case kJSONFloat: jsval = JS_NewFloat64(ctx->js, value.data.floatval); break;
|
||||
case kJSONString: jsval = JS_NewString(ctx->js, value.data.stringval); break;
|
||||
default: jsval = JS_UNDEFINED; break;
|
||||
default: jsval = JS_NULL; break;
|
||||
}
|
||||
JS_SetPropertyUint32(ctx->js, container, pos, jsval);
|
||||
}
|
||||
@@ -136,7 +136,7 @@ static void encode_js_array(json_encoder *enc, JSContext *js, JSValue arr) {
|
||||
}
|
||||
|
||||
static void encode_js_value(json_encoder *enc, JSContext *js, JSValue val) {
|
||||
if (JS_IsNull(val) || JS_IsUndefined(val)) {
|
||||
if (JS_IsNull(val)) {
|
||||
enc->writeNull(enc);
|
||||
} else if (JS_IsBool(val)) {
|
||||
if (JS_ToBool(js, val)) enc->writeTrue(enc);
|
||||
@@ -163,7 +163,7 @@ static void encode_js_value(json_encoder *enc, JSContext *js, JSValue val) {
|
||||
|
||||
JSC_SCALL(json_decodeString,
|
||||
if (!pd_json) return JS_ThrowInternalError(js, "json not initialized");
|
||||
JsonDecodeCtx ctx = { js, JS_UNDEFINED, {}, 0 };
|
||||
JsonDecodeCtx ctx = { js, JS_NULL, {}, 0 };
|
||||
json_decoder decoder = {0};
|
||||
decoder.decodeError = json_decode_error;
|
||||
decoder.willDecodeSublist = json_decode_will_sublist;
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
JSC_CCALL(lua_stop,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
pd_lua->stop();
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_start,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
pd_lua->start();
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_getArgCount,
|
||||
@@ -73,25 +73,25 @@ JSC_CCALL(lua_getArgBytes,
|
||||
JSC_CCALL(lua_pushNil,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
pd_lua->pushNil();
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_pushBool,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
pd_lua->pushBool(JS_ToBool(js, argv[0]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_pushInt,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
pd_lua->pushInt((int)js2number(js, argv[0]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_pushFloat,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
pd_lua->pushFloat((float)js2number(js, argv[0]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_SCALL(lua_pushString,
|
||||
@@ -105,7 +105,7 @@ JSC_CCALL(lua_pushBytes,
|
||||
const char *data = js_get_blob_data(js, &len, argv[0]);
|
||||
if (data == (void*)-1) return JS_EXCEPTION;
|
||||
pd_lua->pushBytes(data, len);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_SCALL(lua_callFunction,
|
||||
|
||||
@@ -30,7 +30,7 @@ JSC_CCALL(network_setEnabled,
|
||||
if (!pd_network) return JS_ThrowInternalError(js, "network not initialized");
|
||||
// Note: callback not implemented for simplicity
|
||||
pd_network->setEnabled(JS_ToBool(js, argv[0]), NULL);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
// --- HTTP Functions ---
|
||||
@@ -54,25 +54,25 @@ JSC_CCALL(http_release,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
HTTPConnection *conn = js2http(js, argv[0]);
|
||||
if (conn) pd_network->http->release(conn);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(http_setConnectTimeout,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
pd_network->http->setConnectTimeout(js2http(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(http_setKeepAlive,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
pd_network->http->setKeepAlive(js2http(js, argv[0]), JS_ToBool(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(http_setByteRange,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
pd_network->http->setByteRange(js2http(js, argv[0]), (int)js2number(js, argv[1]), (int)js2number(js, argv[2]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_SCALL(http_get,
|
||||
@@ -126,13 +126,13 @@ JSC_CCALL(http_getBytesAvailable,
|
||||
JSC_CCALL(http_setReadTimeout,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
pd_network->http->setReadTimeout(js2http(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(http_setReadBufferSize,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
pd_network->http->setReadBufferSize(js2http(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(http_read,
|
||||
@@ -154,7 +154,7 @@ JSC_CCALL(http_read,
|
||||
JSC_CCALL(http_close,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
pd_network->http->close(js2http(js, argv[0]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
// --- TCP Functions ---
|
||||
@@ -178,7 +178,7 @@ JSC_CCALL(tcp_release,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
TCPConnection *conn = js2tcp(js, argv[0]);
|
||||
if (conn) pd_network->tcp->release(conn);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(tcp_getError,
|
||||
@@ -189,7 +189,7 @@ JSC_CCALL(tcp_getError,
|
||||
JSC_CCALL(tcp_setConnectTimeout,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
pd_network->tcp->setConnectTimeout(js2tcp(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(tcp_close,
|
||||
@@ -200,13 +200,13 @@ JSC_CCALL(tcp_close,
|
||||
JSC_CCALL(tcp_setReadTimeout,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
pd_network->tcp->setReadTimeout(js2tcp(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(tcp_setReadBufferSize,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
pd_network->tcp->setReadBufferSize(js2tcp(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(tcp_getBytesAvailable,
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
// A more robust implementation would use promises or callback registration.
|
||||
|
||||
static JSContext *g_scoreboard_js = NULL;
|
||||
static JSValue g_add_score_callback = JS_UNDEFINED;
|
||||
static JSValue g_personal_best_callback = JS_UNDEFINED;
|
||||
static JSValue g_boards_list_callback = JS_UNDEFINED;
|
||||
static JSValue g_scores_callback = JS_UNDEFINED;
|
||||
static JSValue g_add_score_callback = JS_NULL;
|
||||
static JSValue g_personal_best_callback = JS_NULL;
|
||||
static JSValue g_boards_list_callback = JS_NULL;
|
||||
static JSValue g_scores_callback = JS_NULL;
|
||||
|
||||
static JSValue score_to_js(JSContext *js, PDScore *score) {
|
||||
if (!score) return JS_NULL;
|
||||
@@ -25,29 +25,29 @@ static JSValue score_to_js(JSContext *js, PDScore *score) {
|
||||
}
|
||||
|
||||
static void add_score_cb(PDScore *score, const char *errorMessage) {
|
||||
if (!g_scoreboard_js || JS_IsUndefined(g_add_score_callback)) return;
|
||||
if (!g_scoreboard_js || JS_IsNull(g_add_score_callback)) return;
|
||||
JSValue args[2];
|
||||
args[0] = score_to_js(g_scoreboard_js, score);
|
||||
args[1] = errorMessage ? JS_NewString(g_scoreboard_js, errorMessage) : JS_NULL;
|
||||
JSValue ret = JS_Call(g_scoreboard_js, g_add_score_callback, JS_UNDEFINED, 2, args);
|
||||
JSValue ret = JS_Call(g_scoreboard_js, g_add_score_callback, JS_NULL, 2, args);
|
||||
JS_FreeValue(g_scoreboard_js, ret);
|
||||
JS_FreeValue(g_scoreboard_js, args[0]);
|
||||
JS_FreeValue(g_scoreboard_js, args[1]);
|
||||
}
|
||||
|
||||
static void personal_best_cb(PDScore *score, const char *errorMessage) {
|
||||
if (!g_scoreboard_js || JS_IsUndefined(g_personal_best_callback)) return;
|
||||
if (!g_scoreboard_js || JS_IsNull(g_personal_best_callback)) return;
|
||||
JSValue args[2];
|
||||
args[0] = score_to_js(g_scoreboard_js, score);
|
||||
args[1] = errorMessage ? JS_NewString(g_scoreboard_js, errorMessage) : JS_NULL;
|
||||
JSValue ret = JS_Call(g_scoreboard_js, g_personal_best_callback, JS_UNDEFINED, 2, args);
|
||||
JSValue ret = JS_Call(g_scoreboard_js, g_personal_best_callback, JS_NULL, 2, args);
|
||||
JS_FreeValue(g_scoreboard_js, ret);
|
||||
JS_FreeValue(g_scoreboard_js, args[0]);
|
||||
JS_FreeValue(g_scoreboard_js, args[1]);
|
||||
}
|
||||
|
||||
static void boards_list_cb(PDBoardsList *boards, const char *errorMessage) {
|
||||
if (!g_scoreboard_js || JS_IsUndefined(g_boards_list_callback)) return;
|
||||
if (!g_scoreboard_js || JS_IsNull(g_boards_list_callback)) return;
|
||||
JSValue args[2];
|
||||
if (boards) {
|
||||
JSValue arr = JS_NewArray(g_scoreboard_js);
|
||||
@@ -64,14 +64,14 @@ static void boards_list_cb(PDBoardsList *boards, const char *errorMessage) {
|
||||
args[0] = JS_NULL;
|
||||
}
|
||||
args[1] = errorMessage ? JS_NewString(g_scoreboard_js, errorMessage) : JS_NULL;
|
||||
JSValue ret = JS_Call(g_scoreboard_js, g_boards_list_callback, JS_UNDEFINED, 2, args);
|
||||
JSValue ret = JS_Call(g_scoreboard_js, g_boards_list_callback, JS_NULL, 2, args);
|
||||
JS_FreeValue(g_scoreboard_js, ret);
|
||||
JS_FreeValue(g_scoreboard_js, args[0]);
|
||||
JS_FreeValue(g_scoreboard_js, args[1]);
|
||||
}
|
||||
|
||||
static void scores_cb(PDScoresList *scores, const char *errorMessage) {
|
||||
if (!g_scoreboard_js || JS_IsUndefined(g_scores_callback)) return;
|
||||
if (!g_scoreboard_js || JS_IsNull(g_scores_callback)) return;
|
||||
JSValue args[2];
|
||||
if (scores) {
|
||||
JSValue obj = JS_NewObject(g_scoreboard_js);
|
||||
@@ -91,7 +91,7 @@ static void scores_cb(PDScoresList *scores, const char *errorMessage) {
|
||||
args[0] = JS_NULL;
|
||||
}
|
||||
args[1] = errorMessage ? JS_NewString(g_scoreboard_js, errorMessage) : JS_NULL;
|
||||
JSValue ret = JS_Call(g_scoreboard_js, g_scores_callback, JS_UNDEFINED, 2, args);
|
||||
JSValue ret = JS_Call(g_scoreboard_js, g_scores_callback, JS_NULL, 2, args);
|
||||
JS_FreeValue(g_scoreboard_js, ret);
|
||||
JS_FreeValue(g_scoreboard_js, args[0]);
|
||||
JS_FreeValue(g_scoreboard_js, args[1]);
|
||||
@@ -124,7 +124,7 @@ JSC_CCALL(scoreboards_freeScore,
|
||||
if (!pd_scoreboards) return JS_ThrowInternalError(js, "scoreboards not initialized");
|
||||
// Note: PDScore from callbacks is managed by Playdate, this is for user-allocated scores
|
||||
// In practice, JS doesn't allocate PDScore directly, so this is a no-op wrapper
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(scoreboards_getScoreboards,
|
||||
@@ -140,7 +140,7 @@ JSC_CCALL(scoreboards_getScoreboards,
|
||||
JSC_CCALL(scoreboards_freeBoardsList,
|
||||
if (!pd_scoreboards) return JS_ThrowInternalError(js, "scoreboards not initialized");
|
||||
// Managed by Playdate after callback
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_SCALL(scoreboards_getScores,
|
||||
@@ -156,7 +156,7 @@ JSC_SCALL(scoreboards_getScores,
|
||||
JSC_CCALL(scoreboards_freeScoresList,
|
||||
if (!pd_scoreboards) return JS_ThrowInternalError(js, "scoreboards not initialized");
|
||||
// Managed by Playdate after callback
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
static const JSCFunctionListEntry js_scoreboards_funcs[] = {
|
||||
|
||||
@@ -47,7 +47,7 @@ JSC_CCALL(sound_removeChannel,
|
||||
JSC_CCALL(sound_setOutputsActive,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->setOutputsActive(JS_ToBool(js, argv[0]), JS_ToBool(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_getError,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -65,7 +65,7 @@ JSC_CCALL(sound_freeFilePlayer,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
FilePlayer *p = js2fileplayer(js, argv[0]);
|
||||
if (p) pd_sound->fileplayer->freePlayer(p);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_SCALL(sound_loadIntoFilePlayer,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -85,17 +85,17 @@ JSC_CCALL(sound_filePlayerIsPlaying,
|
||||
JSC_CCALL(sound_filePlayerPause,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->fileplayer->pause(js2fileplayer(js, argv[0]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerStop,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->fileplayer->stop(js2fileplayer(js, argv[0]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerSetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->fileplayer->setVolume(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerGetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -112,7 +112,7 @@ JSC_CCALL(sound_filePlayerGetLength,
|
||||
JSC_CCALL(sound_filePlayerSetOffset,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->fileplayer->setOffset(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerGetOffset,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -121,7 +121,7 @@ JSC_CCALL(sound_filePlayerGetOffset,
|
||||
JSC_CCALL(sound_filePlayerSetRate,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->fileplayer->setRate(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerGetRate,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -130,7 +130,7 @@ JSC_CCALL(sound_filePlayerGetRate,
|
||||
JSC_CCALL(sound_filePlayerSetLoopRange,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->fileplayer->setLoopRange(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerDidUnderrun,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -139,12 +139,12 @@ JSC_CCALL(sound_filePlayerDidUnderrun,
|
||||
JSC_CCALL(sound_filePlayerSetStopOnUnderrun,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->fileplayer->setStopOnUnderrun(js2fileplayer(js, argv[0]), JS_ToBool(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerSetBufferLength,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->fileplayer->setBufferLength(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
// --- Sample ---
|
||||
@@ -157,7 +157,7 @@ JSC_CCALL(sound_freeSample,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
AudioSample *s = js2sample(js, argv[0]);
|
||||
if (s) pd_sound->sample->freeSample(s);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_getSampleLength,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -179,12 +179,12 @@ JSC_CCALL(sound_freeSamplePlayer,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
SamplePlayer *p = js2sampleplayer(js, argv[0]);
|
||||
if (p) pd_sound->sampleplayer->freePlayer(p);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerSetSample,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->sampleplayer->setSample(js2sampleplayer(js, argv[0]), js2sample(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerPlay,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -200,12 +200,12 @@ JSC_CCALL(sound_samplePlayerIsPlaying,
|
||||
JSC_CCALL(sound_samplePlayerStop,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->sampleplayer->stop(js2sampleplayer(js, argv[0]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerSetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->sampleplayer->setVolume(js2sampleplayer(js, argv[0]), (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerGetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -222,7 +222,7 @@ JSC_CCALL(sound_samplePlayerGetLength,
|
||||
JSC_CCALL(sound_samplePlayerSetOffset,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->sampleplayer->setOffset(js2sampleplayer(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerGetOffset,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -231,7 +231,7 @@ JSC_CCALL(sound_samplePlayerGetOffset,
|
||||
JSC_CCALL(sound_samplePlayerSetRate,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->sampleplayer->setRate(js2sampleplayer(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerGetRate,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -240,12 +240,12 @@ JSC_CCALL(sound_samplePlayerGetRate,
|
||||
JSC_CCALL(sound_samplePlayerSetPlayRange,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->sampleplayer->setPlayRange(js2sampleplayer(js, argv[0]), (int)js2number(js, argv[1]), (int)js2number(js, argv[2]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerSetPaused,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->sampleplayer->setPaused(js2sampleplayer(js, argv[0]), JS_ToBool(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
// --- Synth ---
|
||||
@@ -258,37 +258,37 @@ JSC_CCALL(sound_freeSynth,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
PDSynth *s = js2synth(js, argv[0]);
|
||||
if (s) pd_sound->synth->freeSynth(s);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthSetWaveform,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->synth->setWaveform(js2synth(js, argv[0]), (SoundWaveform)(int)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthSetAttackTime,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->synth->setAttackTime(js2synth(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthSetDecayTime,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->synth->setDecayTime(js2synth(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthSetSustainLevel,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->synth->setSustainLevel(js2synth(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthSetReleaseTime,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->synth->setReleaseTime(js2synth(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthSetTranspose,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->synth->setTranspose(js2synth(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthPlayNote,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -298,7 +298,7 @@ JSC_CCALL(sound_synthPlayNote,
|
||||
float len = argc > 3 ? (float)js2number(js, argv[3]) : -1.0f;
|
||||
uint32_t when = argc > 4 ? (uint32_t)js2number(js, argv[4]) : 0;
|
||||
pd_sound->synth->playNote(s, freq, vel, len, when);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthPlayMIDINote,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -308,22 +308,22 @@ JSC_CCALL(sound_synthPlayMIDINote,
|
||||
float len = argc > 3 ? (float)js2number(js, argv[3]) : -1.0f;
|
||||
uint32_t when = argc > 4 ? (uint32_t)js2number(js, argv[4]) : 0;
|
||||
pd_sound->synth->playMIDINote(s, note, vel, len, when);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthNoteOff,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->synth->noteOff(js2synth(js, argv[0]), argc > 1 ? (uint32_t)js2number(js, argv[1]) : 0);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthStop,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->synth->stop(js2synth(js, argv[0]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthSetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->synth->setVolume(js2synth(js, argv[0]), (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthGetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -356,12 +356,12 @@ JSC_CCALL(sound_freeChannel,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
SoundChannel *ch = js2channel(js, argv[0]);
|
||||
if (ch) pd_sound->channel->freeChannel(ch);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_channelSetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->channel->setVolume(js2channel(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_channelGetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
@@ -370,7 +370,7 @@ JSC_CCALL(sound_channelGetVolume,
|
||||
JSC_CCALL(sound_channelSetPan,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
pd_sound->channel->setPan(js2channel(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
static const JSCFunctionListEntry js_sound_funcs[] = {
|
||||
|
||||
@@ -23,19 +23,19 @@ static LCDBitmap* js2bitmap(JSContext *js, JSValueConst val) {
|
||||
JSC_CCALL(sprite_setAlwaysRedraw,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
pd_sprite->setAlwaysRedraw(JS_ToBool(js, argv[0]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_drawSprites,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
pd_sprite->drawSprites();
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_updateAndDrawSprites,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
pd_sprite->updateAndDrawSprites();
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_newSprite,
|
||||
@@ -49,7 +49,7 @@ JSC_CCALL(sprite_freeSprite,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (s) pd_sprite->freeSprite(s);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_copy,
|
||||
@@ -65,7 +65,7 @@ JSC_CCALL(sprite_addSprite,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->addSprite(s);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_removeSprite,
|
||||
@@ -73,13 +73,13 @@ JSC_CCALL(sprite_removeSprite,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->removeSprite(s);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_removeAllSprites,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
pd_sprite->removeAllSprites();
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getSpriteCount,
|
||||
@@ -94,7 +94,7 @@ JSC_CCALL(sprite_setBounds,
|
||||
PDRect bounds = { (float)js2number(js, argv[1]), (float)js2number(js, argv[2]),
|
||||
(float)js2number(js, argv[3]), (float)js2number(js, argv[4]) };
|
||||
pd_sprite->setBounds(s, bounds);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getBounds,
|
||||
@@ -115,7 +115,7 @@ JSC_CCALL(sprite_moveTo,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->moveTo(s, (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_moveBy,
|
||||
@@ -123,7 +123,7 @@ JSC_CCALL(sprite_moveBy,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->moveBy(s, (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setImage,
|
||||
@@ -133,7 +133,7 @@ JSC_CCALL(sprite_setImage,
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
LCDBitmapFlip flip = argc > 2 ? (LCDBitmapFlip)(int)js2number(js, argv[2]) : kBitmapUnflipped;
|
||||
pd_sprite->setImage(s, img, flip);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getImage,
|
||||
@@ -149,7 +149,7 @@ JSC_CCALL(sprite_setSize,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->setSize(s, (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setZIndex,
|
||||
@@ -157,7 +157,7 @@ JSC_CCALL(sprite_setZIndex,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->setZIndex(s, (int16_t)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getZIndex,
|
||||
@@ -172,7 +172,7 @@ JSC_CCALL(sprite_setDrawMode,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->setDrawMode(s, (LCDBitmapDrawMode)(int)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setImageFlip,
|
||||
@@ -180,7 +180,7 @@ JSC_CCALL(sprite_setImageFlip,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->setImageFlip(s, (LCDBitmapFlip)(int)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getImageFlip,
|
||||
@@ -195,7 +195,7 @@ JSC_CCALL(sprite_setVisible,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->setVisible(s, JS_ToBool(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_isVisible,
|
||||
@@ -210,7 +210,7 @@ JSC_CCALL(sprite_setOpaque,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->setOpaque(s, JS_ToBool(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_markDirty,
|
||||
@@ -218,7 +218,7 @@ JSC_CCALL(sprite_markDirty,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->markDirty(s);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setTag,
|
||||
@@ -226,7 +226,7 @@ JSC_CCALL(sprite_setTag,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->setTag(s, (uint8_t)js2number(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getTag,
|
||||
@@ -241,7 +241,7 @@ JSC_CCALL(sprite_setIgnoresDrawOffset,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->setIgnoresDrawOffset(s, JS_ToBool(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getPosition,
|
||||
@@ -261,7 +261,7 @@ JSC_CCALL(sprite_setCenter,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->setCenter(s, (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getCenter,
|
||||
@@ -281,7 +281,7 @@ JSC_CCALL(sprite_getCenter,
|
||||
JSC_CCALL(sprite_resetCollisionWorld,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
pd_sprite->resetCollisionWorld();
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setCollideRect,
|
||||
@@ -291,7 +291,7 @@ JSC_CCALL(sprite_setCollideRect,
|
||||
PDRect rect = { (float)js2number(js, argv[1]), (float)js2number(js, argv[2]),
|
||||
(float)js2number(js, argv[3]), (float)js2number(js, argv[4]) };
|
||||
pd_sprite->setCollideRect(s, rect);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getCollideRect,
|
||||
@@ -312,7 +312,7 @@ JSC_CCALL(sprite_clearCollideRect,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->clearCollideRect(s);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setCollisionsEnabled,
|
||||
@@ -320,7 +320,7 @@ JSC_CCALL(sprite_setCollisionsEnabled,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->setCollisionsEnabled(s, JS_ToBool(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_collisionsEnabled,
|
||||
@@ -335,7 +335,7 @@ JSC_CCALL(sprite_setUpdatesEnabled,
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
pd_sprite->setUpdatesEnabled(s, JS_ToBool(js, argv[1]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_updatesEnabled,
|
||||
|
||||
@@ -14,7 +14,7 @@ JSC_CCALL(sys_logToConsole,
|
||||
pd_sys->logToConsole("%s", str);
|
||||
JS_FreeCString(js, str);
|
||||
}
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_error,
|
||||
@@ -24,7 +24,7 @@ JSC_CCALL(sys_error,
|
||||
pd_sys->error("%s", str);
|
||||
JS_FreeCString(js, str);
|
||||
}
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getLanguage,
|
||||
@@ -53,7 +53,7 @@ JSC_CCALL(sys_drawFPS,
|
||||
int x = (int)js2number(js, argv[0]);
|
||||
int y = (int)js2number(js, argv[1]);
|
||||
pd_sys->drawFPS(x, y);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getButtonState,
|
||||
@@ -71,7 +71,7 @@ JSC_CCALL(sys_setPeripheralsEnabled,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
PDPeripherals mask = (PDPeripherals)(int)js2number(js, argv[0]);
|
||||
pd_sys->setPeripheralsEnabled(mask);
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getAccelerometer,
|
||||
@@ -115,7 +115,7 @@ JSC_CCALL(sys_getFlipped,
|
||||
JSC_CCALL(sys_setAutoLockDisabled,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
pd_sys->setAutoLockDisabled(JS_ToBool(js, argv[0]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getReduceFlashing,
|
||||
@@ -131,7 +131,7 @@ JSC_CCALL(sys_getElapsedTime,
|
||||
JSC_CCALL(sys_resetElapsedTime,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
pd_sys->resetElapsedTime();
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getBatteryPercentage,
|
||||
@@ -185,13 +185,13 @@ JSC_CCALL(sys_convertDateTimeToEpoch,
|
||||
JSC_CCALL(sys_clearICache,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
pd_sys->clearICache();
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_delay,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
pd_sys->delay((uint32_t)js2number(js, argv[0]));
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_SCALL(sys_restartGame,
|
||||
@@ -224,7 +224,7 @@ JSC_CCALL(sys_getSystemInfo,
|
||||
JSC_CCALL(sys_removeAllMenuItems,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
pd_sys->removeAllMenuItems();
|
||||
return JS_UNDEFINED;
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
static const JSCFunctionListEntry js_sys_funcs[] = {
|
||||
|
||||
Reference in New Issue
Block a user