disruption
This commit is contained in:
@@ -7,48 +7,48 @@
|
||||
// --- Display API Wrappers ---
|
||||
|
||||
JSC_CCALL(display_getWidth,
|
||||
if (!pd_display) return JS_ThrowInternalError(js, "display not initialized");
|
||||
if (!pd_display) return JS_RaiseDisrupt(js, "display not initialized");
|
||||
return JS_NewInt32(js, pd_display->getWidth());
|
||||
)
|
||||
|
||||
JSC_CCALL(display_getHeight,
|
||||
if (!pd_display) return JS_ThrowInternalError(js, "display not initialized");
|
||||
if (!pd_display) return JS_RaiseDisrupt(js, "display not initialized");
|
||||
return JS_NewInt32(js, pd_display->getHeight());
|
||||
)
|
||||
|
||||
JSC_CCALL(display_setRefreshRate,
|
||||
if (!pd_display) return JS_ThrowInternalError(js, "display not initialized");
|
||||
if (!pd_display) return JS_RaiseDisrupt(js, "display not initialized");
|
||||
float rate = (float)js2number(js, argv[0]);
|
||||
pd_display->setRefreshRate(rate);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(display_getRefreshRate,
|
||||
if (!pd_display) return JS_ThrowInternalError(js, "display not initialized");
|
||||
if (!pd_display) return JS_RaiseDisrupt(js, "display not initialized");
|
||||
return JS_NewFloat64(js, pd_display->getRefreshRate());
|
||||
)
|
||||
|
||||
JSC_CCALL(display_getFPS,
|
||||
if (!pd_display) return JS_ThrowInternalError(js, "display not initialized");
|
||||
if (!pd_display) return JS_RaiseDisrupt(js, "display not initialized");
|
||||
return JS_NewFloat64(js, pd_display->getFPS());
|
||||
)
|
||||
|
||||
JSC_CCALL(display_setInverted,
|
||||
if (!pd_display) return JS_ThrowInternalError(js, "display not initialized");
|
||||
if (!pd_display) return JS_RaiseDisrupt(js, "display not initialized");
|
||||
int flag = JS_ToBool(js, argv[0]);
|
||||
pd_display->setInverted(flag);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(display_setScale,
|
||||
if (!pd_display) return JS_ThrowInternalError(js, "display not initialized");
|
||||
if (!pd_display) return JS_RaiseDisrupt(js, "display not initialized");
|
||||
unsigned int scale = (unsigned int)js2number(js, argv[0]);
|
||||
pd_display->setScale(scale);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(display_setMosaic,
|
||||
if (!pd_display) return JS_ThrowInternalError(js, "display not initialized");
|
||||
if (!pd_display) return JS_RaiseDisrupt(js, "display not initialized");
|
||||
unsigned int x = (unsigned int)js2number(js, argv[0]);
|
||||
unsigned int y = (unsigned int)js2number(js, argv[1]);
|
||||
pd_display->setMosaic(x, y);
|
||||
@@ -56,7 +56,7 @@ JSC_CCALL(display_setMosaic,
|
||||
)
|
||||
|
||||
JSC_CCALL(display_setFlipped,
|
||||
if (!pd_display) return JS_ThrowInternalError(js, "display not initialized");
|
||||
if (!pd_display) return JS_RaiseDisrupt(js, "display not initialized");
|
||||
int x = JS_ToBool(js, argv[0]);
|
||||
int y = JS_ToBool(js, argv[1]);
|
||||
pd_display->setFlipped(x, y);
|
||||
@@ -64,7 +64,7 @@ JSC_CCALL(display_setFlipped,
|
||||
)
|
||||
|
||||
JSC_CCALL(display_setOffset,
|
||||
if (!pd_display) return JS_ThrowInternalError(js, "display not initialized");
|
||||
if (!pd_display) return JS_RaiseDisrupt(js, "display not initialized");
|
||||
int x = (int)js2number(js, argv[0]);
|
||||
int y = (int)js2number(js, argv[1]);
|
||||
pd_display->setOffset(x, y);
|
||||
|
||||
@@ -17,13 +17,13 @@ static SDFile* js2sdfile(JSContext *js, JSValueConst val) {
|
||||
// --- File Functions ---
|
||||
|
||||
JSC_CCALL(file_geterr,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
const char *err = pd_file->geterr();
|
||||
return err ? JS_NewString(js, err) : JS_NULL;
|
||||
)
|
||||
|
||||
JSC_SCALL(file_stat,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
FileStat st;
|
||||
if (pd_file->stat(str, &st) != 0) {
|
||||
ret = JS_NULL;
|
||||
@@ -42,18 +42,18 @@ JSC_SCALL(file_stat,
|
||||
)
|
||||
|
||||
JSC_SCALL(file_mkdir,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
ret = JS_NewBool(js, pd_file->mkdir(str) == 0);
|
||||
)
|
||||
|
||||
JSC_SCALL(file_unlink,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
int recursive = argc > 1 ? JS_ToBool(js, argv[1]) : 0;
|
||||
ret = JS_NewBool(js, pd_file->unlink(str, recursive) == 0);
|
||||
)
|
||||
|
||||
JSC_SCALL(file_rename,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
const char *to = JS_ToCString(js, argv[1]);
|
||||
int result = pd_file->rename(str, to);
|
||||
JS_FreeCString(js, to);
|
||||
@@ -61,7 +61,7 @@ JSC_SCALL(file_rename,
|
||||
)
|
||||
|
||||
JSC_SCALL(file_open,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
FileOptions mode = kFileRead;
|
||||
if (argc > 1) mode = (FileOptions)(int)js2number(js, argv[1]);
|
||||
SDFile *f = pd_file->open(str, mode);
|
||||
@@ -69,17 +69,17 @@ JSC_SCALL(file_open,
|
||||
)
|
||||
|
||||
JSC_CCALL(file_close,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
SDFile *f = js2sdfile(js, argv[0]);
|
||||
return JS_NewBool(js, pd_file->close(f) == 0);
|
||||
)
|
||||
|
||||
JSC_CCALL(file_read,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
SDFile *f = js2sdfile(js, argv[0]);
|
||||
unsigned int len = (unsigned int)js2number(js, argv[1]);
|
||||
void *buf = malloc(len);
|
||||
if (!buf) return JS_ThrowInternalError(js, "malloc failed");
|
||||
if (!buf) return JS_RaiseDisrupt(js, "malloc failed");
|
||||
int read = pd_file->read(f, buf, len);
|
||||
if (read < 0) {
|
||||
free(buf);
|
||||
@@ -91,7 +91,7 @@ JSC_CCALL(file_read,
|
||||
)
|
||||
|
||||
JSC_CCALL(file_write,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
SDFile *f = js2sdfile(js, argv[0]);
|
||||
size_t len;
|
||||
const void *data = js_get_blob_data(js, &len, argv[1]);
|
||||
@@ -101,19 +101,19 @@ JSC_CCALL(file_write,
|
||||
)
|
||||
|
||||
JSC_CCALL(file_flush,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
SDFile *f = js2sdfile(js, argv[0]);
|
||||
return JS_NewBool(js, pd_file->flush(f) == 0);
|
||||
)
|
||||
|
||||
JSC_CCALL(file_tell,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
SDFile *f = js2sdfile(js, argv[0]);
|
||||
return JS_NewInt32(js, pd_file->tell(f));
|
||||
)
|
||||
|
||||
JSC_CCALL(file_seek,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
SDFile *f = js2sdfile(js, argv[0]);
|
||||
int pos = (int)js2number(js, argv[1]);
|
||||
int whence = argc > 2 ? (int)js2number(js, argv[2]) : SEEK_SET;
|
||||
@@ -132,7 +132,7 @@ static void listfiles_cb(const char *path, void *userdata) {
|
||||
}
|
||||
|
||||
JSC_SCALL(file_listfiles,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
int showhidden = argc > 1 ? JS_ToBool(js, argv[1]) : 0;
|
||||
JSValue arr = JS_NewArray(js);
|
||||
struct listfiles_ctx ctx = { js, arr, 0 };
|
||||
|
||||
@@ -27,76 +27,76 @@ static LCDFont* js2font(JSContext *js, JSValueConst val) {
|
||||
// --- Drawing Functions ---
|
||||
|
||||
JSC_CCALL(gfx_clear,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
LCDColor color = (LCDColor)js2number(js, argv[0]);
|
||||
pd_gfx->clear(color);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setBackgroundColor,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
LCDSolidColor color = (LCDSolidColor)(int)js2number(js, argv[0]);
|
||||
pd_gfx->setBackgroundColor(color);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setDrawMode,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
LCDBitmapDrawMode mode = (LCDBitmapDrawMode)(int)js2number(js, argv[0]);
|
||||
LCDBitmapDrawMode prev = pd_gfx->setDrawMode(mode);
|
||||
return JS_NewInt32(js, prev);
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setDrawOffset,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
pd_gfx->setDrawOffset((int)js2number(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setClipRect,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(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_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_clearClipRect,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
pd_gfx->clearClipRect();
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setLineCapStyle,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
pd_gfx->setLineCapStyle((LCDLineCapStyle)(int)js2number(js, argv[0]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setFont,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
pd_gfx->setFont(js2font(js, argv[0]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setTextTracking,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
pd_gfx->setTextTracking((int)js2number(js, argv[0]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_getTextTracking,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
return JS_NewInt32(js, pd_gfx->getTextTracking());
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_pushContext,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
pd_gfx->pushContext(argc > 0 ? js2bitmap(js, argv[0]) : NULL);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_popContext,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
pd_gfx->popContext();
|
||||
return JS_NULL;
|
||||
)
|
||||
@@ -104,16 +104,16 @@ JSC_CCALL(gfx_popContext,
|
||||
// --- Drawing Primitives ---
|
||||
|
||||
JSC_CCALL(gfx_drawBitmap,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
LCDBitmap *bmp = js2bitmap(js, argv[0]);
|
||||
if (!bmp) return JS_ThrowTypeError(js, "invalid bitmap");
|
||||
if (!bmp) return JS_RaiseDisrupt(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_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_drawLine,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
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]));
|
||||
@@ -121,7 +121,7 @@ JSC_CCALL(gfx_drawLine,
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_drawRect,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
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]));
|
||||
@@ -129,7 +129,7 @@ JSC_CCALL(gfx_drawRect,
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_fillRect,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
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]));
|
||||
@@ -137,7 +137,7 @@ JSC_CCALL(gfx_fillRect,
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_fillTriangle,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
pd_gfx->fillTriangle((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]), (int)js2number(js, argv[5]),
|
||||
@@ -146,7 +146,7 @@ JSC_CCALL(gfx_fillTriangle,
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_drawEllipse,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
pd_gfx->drawEllipse((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]), (float)js2number(js, argv[5]),
|
||||
@@ -155,7 +155,7 @@ JSC_CCALL(gfx_drawEllipse,
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_fillEllipse,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
pd_gfx->fillEllipse((int)js2number(js, argv[0]), (int)js2number(js, argv[1]),
|
||||
(int)js2number(js, argv[2]), (int)js2number(js, argv[3]),
|
||||
(float)js2number(js, argv[4]), (float)js2number(js, argv[5]),
|
||||
@@ -164,25 +164,25 @@ JSC_CCALL(gfx_fillEllipse,
|
||||
)
|
||||
|
||||
JSC_SCALL(gfx_drawText,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
int w = pd_gfx->drawText(str, strlen(str), kUTF8Encoding,
|
||||
(int)js2number(js, argv[1]), (int)js2number(js, argv[2]));
|
||||
ret = JS_NewInt32(js, w);
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_drawScaledBitmap,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
LCDBitmap *bmp = js2bitmap(js, argv[0]);
|
||||
if (!bmp) return JS_ThrowTypeError(js, "invalid bitmap");
|
||||
if (!bmp) return JS_RaiseDisrupt(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_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_drawRotatedBitmap,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
LCDBitmap *bmp = js2bitmap(js, argv[0]);
|
||||
if (!bmp) return JS_ThrowTypeError(js, "invalid bitmap");
|
||||
if (!bmp) return JS_RaiseDisrupt(js, "invalid bitmap");
|
||||
pd_gfx->drawRotatedBitmap(bmp, (int)js2number(js, argv[1]), (int)js2number(js, argv[2]),
|
||||
(float)js2number(js, argv[3]), (float)js2number(js, argv[4]),
|
||||
(float)js2number(js, argv[5]), (float)js2number(js, argv[6]),
|
||||
@@ -191,7 +191,7 @@ JSC_CCALL(gfx_drawRotatedBitmap,
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_setPixel,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
pd_gfx->setPixel((int)js2number(js, argv[0]), (int)js2number(js, argv[1]),
|
||||
(LCDColor)js2number(js, argv[2]));
|
||||
return JS_NULL;
|
||||
@@ -200,48 +200,48 @@ JSC_CCALL(gfx_setPixel,
|
||||
// --- Bitmap Functions ---
|
||||
|
||||
JSC_CCALL(gfx_newBitmap,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
LCDBitmap *bmp = pd_gfx->newBitmap((int)js2number(js, argv[0]), (int)js2number(js, argv[1]),
|
||||
argc > 2 ? (LCDColor)js2number(js, argv[2]) : kColorWhite);
|
||||
if (!bmp) return JS_ThrowInternalError(js, "failed to create bitmap");
|
||||
if (!bmp) return JS_RaiseDisrupt(js, "failed to create bitmap");
|
||||
return JS_NewInt64(js, (int64_t)(intptr_t)bmp);
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_freeBitmap,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
LCDBitmap *bmp = js2bitmap(js, argv[0]);
|
||||
if (bmp) pd_gfx->freeBitmap(bmp);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_SCALL(gfx_loadBitmap,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
const char *err = NULL;
|
||||
LCDBitmap *bmp = pd_gfx->loadBitmap(str, &err);
|
||||
if (!bmp) ret = JS_ThrowInternalError(js, "loadBitmap: %s", err ? err : "unknown");
|
||||
if (!bmp) ret = JS_RaiseDisrupt(js, "loadBitmap: %s", err ? err : "unknown");
|
||||
else ret = JS_NewInt64(js, (int64_t)(intptr_t)bmp);
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_copyBitmap,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
LCDBitmap *bmp = js2bitmap(js, argv[0]);
|
||||
if (!bmp) return JS_ThrowTypeError(js, "invalid bitmap");
|
||||
if (!bmp) return JS_RaiseDisrupt(js, "invalid bitmap");
|
||||
LCDBitmap *copy = pd_gfx->copyBitmap(bmp);
|
||||
return copy ? JS_NewInt64(js, (int64_t)(intptr_t)copy) : JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_clearBitmap,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
LCDBitmap *bmp = js2bitmap(js, argv[0]);
|
||||
if (!bmp) return JS_ThrowTypeError(js, "invalid bitmap");
|
||||
if (!bmp) return JS_RaiseDisrupt(js, "invalid bitmap");
|
||||
pd_gfx->clearBitmap(bmp, argc > 1 ? (LCDColor)js2number(js, argv[1]) : kColorWhite);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_getBitmapData,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
LCDBitmap *bmp = js2bitmap(js, argv[0]);
|
||||
if (!bmp) return JS_ThrowTypeError(js, "invalid bitmap");
|
||||
if (!bmp) return JS_RaiseDisrupt(js, "invalid bitmap");
|
||||
int w, h, rb; uint8_t *mask, *data;
|
||||
pd_gfx->getBitmapData(bmp, &w, &h, &rb, &mask, &data);
|
||||
JSValue obj = JS_NewObject(js);
|
||||
@@ -254,21 +254,21 @@ JSC_CCALL(gfx_getBitmapData,
|
||||
// --- Font Functions ---
|
||||
|
||||
JSC_SCALL(gfx_loadFont,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
const char *err = NULL;
|
||||
LCDFont *font = pd_gfx->loadFont(str, &err);
|
||||
if (!font) ret = JS_ThrowInternalError(js, "loadFont: %s", err ? err : "unknown");
|
||||
if (!font) ret = JS_RaiseDisrupt(js, "loadFont: %s", err ? err : "unknown");
|
||||
else ret = JS_NewInt64(js, (int64_t)(intptr_t)font);
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_getFontHeight,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
LCDFont *font = js2font(js, argv[0]);
|
||||
return JS_NewInt32(js, pd_gfx->getFontHeight(font));
|
||||
)
|
||||
|
||||
JSC_SCALL(gfx_getTextWidth,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
LCDFont *font = argc > 1 ? js2font(js, argv[1]) : NULL;
|
||||
int tracking = argc > 2 ? (int)js2number(js, argv[2]) : 0;
|
||||
ret = JS_NewInt32(js, pd_gfx->getTextWidth(font, str, strlen(str), kUTF8Encoding, tracking));
|
||||
@@ -277,19 +277,19 @@ JSC_SCALL(gfx_getTextWidth,
|
||||
// --- Framebuffer ---
|
||||
|
||||
JSC_CCALL(gfx_display,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
pd_gfx->display();
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_markUpdatedRows,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
pd_gfx->markUpdatedRows((int)js2number(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(gfx_copyFrameBufferBitmap,
|
||||
if (!pd_gfx) return JS_ThrowInternalError(js, "graphics not initialized");
|
||||
if (!pd_gfx) return JS_RaiseDisrupt(js, "graphics not initialized");
|
||||
LCDBitmap *bmp = pd_gfx->copyFrameBufferBitmap();
|
||||
return bmp ? JS_NewInt64(js, (int64_t)(intptr_t)bmp) : JS_NULL;
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ typedef struct {
|
||||
|
||||
static void json_decode_error(json_decoder *decoder, const char *error, int linenum) {
|
||||
JsonDecodeCtx *ctx = (JsonDecodeCtx*)decoder->userdata;
|
||||
ctx->result = JS_ThrowSyntaxError(ctx->js, "JSON parse error at line %d: %s", linenum, error);
|
||||
ctx->result = JS_RaiseDisrupt(ctx->js, "JSON parse error at line %d: %s", linenum, error);
|
||||
}
|
||||
|
||||
static void json_decode_will_sublist(json_decoder *decoder, const char *name, json_value_type type) {
|
||||
@@ -162,7 +162,7 @@ static void encode_js_value(json_encoder *enc, JSContext *js, JSValue val) {
|
||||
// --- API Functions ---
|
||||
|
||||
JSC_SCALL(json_decodeString,
|
||||
if (!pd_json) return JS_ThrowInternalError(js, "json not initialized");
|
||||
if (!pd_json) return JS_RaiseDisrupt(js, "json not initialized");
|
||||
JsonDecodeCtx ctx = { js, JS_NULL, {}, 0 };
|
||||
json_decoder decoder = {0};
|
||||
decoder.decodeError = json_decode_error;
|
||||
@@ -177,9 +177,9 @@ JSC_SCALL(json_decodeString,
|
||||
)
|
||||
|
||||
JSC_CCALL(json_encode,
|
||||
if (!pd_json) return JS_ThrowInternalError(js, "json not initialized");
|
||||
if (!pd_json) return JS_RaiseDisrupt(js, "json not initialized");
|
||||
JsonEncodeCtx ctx = { malloc(256), 0, 256 };
|
||||
if (!ctx.buffer) return JS_ThrowInternalError(js, "malloc failed");
|
||||
if (!ctx.buffer) return JS_RaiseDisrupt(js, "malloc failed");
|
||||
ctx.buffer[0] = '\0';
|
||||
json_encoder enc;
|
||||
int pretty = argc > 1 ? JS_ToBool(js, argv[1]) : 0;
|
||||
|
||||
@@ -9,24 +9,24 @@
|
||||
// --- Lua API Functions ---
|
||||
|
||||
JSC_CCALL(lua_stop,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
pd_lua->stop();
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_start,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
pd_lua->start();
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_getArgCount,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
return JS_NewInt32(js, pd_lua->getArgCount());
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_getArgType,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
int pos = (int)js2number(js, argv[0]);
|
||||
const char *outClass = NULL;
|
||||
enum LuaType type = pd_lua->getArgType(pos, &outClass);
|
||||
@@ -37,33 +37,33 @@ JSC_CCALL(lua_getArgType,
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_argIsNil,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
return JS_NewBool(js, pd_lua->argIsNil((int)js2number(js, argv[0])));
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_getArgBool,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
return JS_NewBool(js, pd_lua->getArgBool((int)js2number(js, argv[0])));
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_getArgInt,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
return JS_NewInt32(js, pd_lua->getArgInt((int)js2number(js, argv[0])));
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_getArgFloat,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
return JS_NewFloat64(js, pd_lua->getArgFloat((int)js2number(js, argv[0])));
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_getArgString,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
const char *str = pd_lua->getArgString((int)js2number(js, argv[0]));
|
||||
return str ? JS_NewString(js, str) : JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_getArgBytes,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
size_t len;
|
||||
const char *bytes = pd_lua->getArgBytes((int)js2number(js, argv[0]), &len);
|
||||
if (!bytes) return JS_NULL;
|
||||
@@ -71,36 +71,36 @@ JSC_CCALL(lua_getArgBytes,
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_pushNil,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
pd_lua->pushNil();
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_pushBool,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
pd_lua->pushBool(JS_ToBool(js, argv[0]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_pushInt,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
pd_lua->pushInt((int)js2number(js, argv[0]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_pushFloat,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
pd_lua->pushFloat((float)js2number(js, argv[0]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_SCALL(lua_pushString,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
pd_lua->pushString(str);
|
||||
)
|
||||
|
||||
JSC_CCALL(lua_pushBytes,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
size_t len;
|
||||
const char *data = js_get_blob_data(js, &len, argv[0]);
|
||||
if (data == (void*)-1) return JS_EXCEPTION;
|
||||
@@ -109,12 +109,12 @@ JSC_CCALL(lua_pushBytes,
|
||||
)
|
||||
|
||||
JSC_SCALL(lua_callFunction,
|
||||
if (!pd_lua) return JS_ThrowInternalError(js, "lua not initialized");
|
||||
if (!pd_lua) return JS_RaiseDisrupt(js, "lua not initialized");
|
||||
int nargs = argc > 1 ? (int)js2number(js, argv[1]) : 0;
|
||||
const char *outerr = NULL;
|
||||
int result = pd_lua->callFunction(str, nargs, &outerr);
|
||||
if (result == 0 && outerr) {
|
||||
ret = JS_ThrowInternalError(js, "Lua error: %s", outerr);
|
||||
ret = JS_RaiseDisrupt(js, "Lua error: %s", outerr);
|
||||
} else {
|
||||
ret = JS_NewBool(js, result);
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ static TCPConnection* js2tcp(JSContext *js, JSValueConst val) {
|
||||
// --- Network Status ---
|
||||
|
||||
JSC_CCALL(network_getStatus,
|
||||
if (!pd_network) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
return JS_NewInt32(js, pd_network->getStatus());
|
||||
)
|
||||
|
||||
JSC_CCALL(network_setEnabled,
|
||||
if (!pd_network) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
// Note: callback not implemented for simplicity
|
||||
pd_network->setEnabled(JS_ToBool(js, argv[0]), NULL);
|
||||
return JS_NULL;
|
||||
@@ -36,7 +36,7 @@ JSC_CCALL(network_setEnabled,
|
||||
// --- HTTP Functions ---
|
||||
|
||||
JSC_SCALL(http_newConnection,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
int port = (int)js2number(js, argv[1]);
|
||||
int usessl = argc > 2 ? JS_ToBool(js, argv[2]) : 0;
|
||||
HTTPConnection *conn = pd_network->http->newConnection(str, port, usessl);
|
||||
@@ -44,39 +44,39 @@ JSC_SCALL(http_newConnection,
|
||||
)
|
||||
|
||||
JSC_CCALL(http_retain,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
HTTPConnection *conn = js2http(js, argv[0]);
|
||||
HTTPConnection *ret_conn = pd_network->http->retain(conn);
|
||||
return ret_conn ? JS_NewInt64(js, (int64_t)(intptr_t)ret_conn) : JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(http_release,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
HTTPConnection *conn = js2http(js, argv[0]);
|
||||
if (conn) pd_network->http->release(conn);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(http_setConnectTimeout,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
pd_network->http->setConnectTimeout(js2http(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(http_setKeepAlive,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
pd_network->http->setKeepAlive(js2http(js, argv[0]), JS_ToBool(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(http_setByteRange,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
pd_network->http->setByteRange(js2http(js, argv[0]), (int)js2number(js, argv[1]), (int)js2number(js, argv[2]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_SCALL(http_get,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
HTTPConnection *conn = js2http(js, argv[0]);
|
||||
const char *headers = argc > 2 ? JS_ToCString(js, argv[2]) : NULL;
|
||||
size_t hlen = headers ? strlen(headers) : 0;
|
||||
@@ -86,7 +86,7 @@ JSC_SCALL(http_get,
|
||||
)
|
||||
|
||||
JSC_SCALL(http_post,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
HTTPConnection *conn = js2http(js, argv[0]);
|
||||
const char *headers = argc > 2 ? JS_ToCString(js, argv[2]) : NULL;
|
||||
size_t hlen = headers ? strlen(headers) : 0;
|
||||
@@ -99,12 +99,12 @@ JSC_SCALL(http_post,
|
||||
)
|
||||
|
||||
JSC_CCALL(http_getError,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
return JS_NewInt32(js, pd_network->http->getError(js2http(js, argv[0])));
|
||||
)
|
||||
|
||||
JSC_CCALL(http_getProgress,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
int read, total;
|
||||
pd_network->http->getProgress(js2http(js, argv[0]), &read, &total);
|
||||
JSValue obj = JS_NewObject(js);
|
||||
@@ -114,33 +114,33 @@ JSC_CCALL(http_getProgress,
|
||||
)
|
||||
|
||||
JSC_CCALL(http_getResponseStatus,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
return JS_NewInt32(js, pd_network->http->getResponseStatus(js2http(js, argv[0])));
|
||||
)
|
||||
|
||||
JSC_CCALL(http_getBytesAvailable,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
return JS_NewInt64(js, pd_network->http->getBytesAvailable(js2http(js, argv[0])));
|
||||
)
|
||||
|
||||
JSC_CCALL(http_setReadTimeout,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
pd_network->http->setReadTimeout(js2http(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(http_setReadBufferSize,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
pd_network->http->setReadBufferSize(js2http(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(http_read,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
HTTPConnection *conn = js2http(js, argv[0]);
|
||||
unsigned int buflen = (unsigned int)js2number(js, argv[1]);
|
||||
void *buf = malloc(buflen);
|
||||
if (!buf) return JS_ThrowInternalError(js, "malloc failed");
|
||||
if (!buf) return JS_RaiseDisrupt(js, "malloc failed");
|
||||
int read = pd_network->http->read(conn, buf, buflen);
|
||||
if (read < 0) {
|
||||
free(buf);
|
||||
@@ -152,7 +152,7 @@ JSC_CCALL(http_read,
|
||||
)
|
||||
|
||||
JSC_CCALL(http_close,
|
||||
if (!pd_network || !pd_network->http) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->http) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
pd_network->http->close(js2http(js, argv[0]));
|
||||
return JS_NULL;
|
||||
)
|
||||
@@ -160,7 +160,7 @@ JSC_CCALL(http_close,
|
||||
// --- TCP Functions ---
|
||||
|
||||
JSC_SCALL(tcp_newConnection,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->tcp) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
int port = (int)js2number(js, argv[1]);
|
||||
int usessl = argc > 2 ? JS_ToBool(js, argv[2]) : 0;
|
||||
TCPConnection *conn = pd_network->tcp->newConnection(str, port, usessl);
|
||||
@@ -168,58 +168,58 @@ JSC_SCALL(tcp_newConnection,
|
||||
)
|
||||
|
||||
JSC_CCALL(tcp_retain,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->tcp) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
TCPConnection *conn = js2tcp(js, argv[0]);
|
||||
TCPConnection *ret_conn = pd_network->tcp->retain(conn);
|
||||
return ret_conn ? JS_NewInt64(js, (int64_t)(intptr_t)ret_conn) : JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(tcp_release,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->tcp) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
TCPConnection *conn = js2tcp(js, argv[0]);
|
||||
if (conn) pd_network->tcp->release(conn);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(tcp_getError,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->tcp) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
return JS_NewInt32(js, pd_network->tcp->getError(js2tcp(js, argv[0])));
|
||||
)
|
||||
|
||||
JSC_CCALL(tcp_setConnectTimeout,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->tcp) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
pd_network->tcp->setConnectTimeout(js2tcp(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(tcp_close,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->tcp) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
return JS_NewInt32(js, pd_network->tcp->close(js2tcp(js, argv[0])));
|
||||
)
|
||||
|
||||
JSC_CCALL(tcp_setReadTimeout,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->tcp) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
pd_network->tcp->setReadTimeout(js2tcp(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(tcp_setReadBufferSize,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->tcp) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
pd_network->tcp->setReadBufferSize(js2tcp(js, argv[0]), (int)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(tcp_getBytesAvailable,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->tcp) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
return JS_NewInt64(js, pd_network->tcp->getBytesAvailable(js2tcp(js, argv[0])));
|
||||
)
|
||||
|
||||
JSC_CCALL(tcp_read,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->tcp) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
TCPConnection *conn = js2tcp(js, argv[0]);
|
||||
size_t len = (size_t)js2number(js, argv[1]);
|
||||
void *buf = malloc(len);
|
||||
if (!buf) return JS_ThrowInternalError(js, "malloc failed");
|
||||
if (!buf) return JS_RaiseDisrupt(js, "malloc failed");
|
||||
int read = pd_network->tcp->read(conn, buf, len);
|
||||
if (read < 0) {
|
||||
free(buf);
|
||||
@@ -231,7 +231,7 @@ JSC_CCALL(tcp_read,
|
||||
)
|
||||
|
||||
JSC_CCALL(tcp_write,
|
||||
if (!pd_network || !pd_network->tcp) return JS_ThrowInternalError(js, "network not initialized");
|
||||
if (!pd_network || !pd_network->tcp) return JS_RaiseDisrupt(js, "network not initialized");
|
||||
TCPConnection *conn = js2tcp(js, argv[0]);
|
||||
size_t len;
|
||||
const void *data = js_get_blob_data(js, &len, argv[1]);
|
||||
|
||||
@@ -100,7 +100,7 @@ static void scores_cb(PDScoresList *scores, const char *errorMessage) {
|
||||
// --- API Functions ---
|
||||
|
||||
JSC_SCALL(scoreboards_addScore,
|
||||
if (!pd_scoreboards) return JS_ThrowInternalError(js, "scoreboards not initialized");
|
||||
if (!pd_scoreboards) return JS_RaiseDisrupt(js, "scoreboards not initialized");
|
||||
uint32_t value = (uint32_t)js2number(js, argv[1]);
|
||||
if (argc > 2 && JS_IsFunction(argv[2])) {
|
||||
g_scoreboard_js = js;
|
||||
@@ -111,7 +111,7 @@ JSC_SCALL(scoreboards_addScore,
|
||||
)
|
||||
|
||||
JSC_SCALL(scoreboards_getPersonalBest,
|
||||
if (!pd_scoreboards) return JS_ThrowInternalError(js, "scoreboards not initialized");
|
||||
if (!pd_scoreboards) return JS_RaiseDisrupt(js, "scoreboards not initialized");
|
||||
if (argc > 1 && JS_IsFunction(argv[1])) {
|
||||
g_scoreboard_js = js;
|
||||
JS_FreeValue(js, g_personal_best_callback);
|
||||
@@ -121,14 +121,14 @@ JSC_SCALL(scoreboards_getPersonalBest,
|
||||
)
|
||||
|
||||
JSC_CCALL(scoreboards_freeScore,
|
||||
if (!pd_scoreboards) return JS_ThrowInternalError(js, "scoreboards not initialized");
|
||||
if (!pd_scoreboards) return JS_RaiseDisrupt(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_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(scoreboards_getScoreboards,
|
||||
if (!pd_scoreboards) return JS_ThrowInternalError(js, "scoreboards not initialized");
|
||||
if (!pd_scoreboards) return JS_RaiseDisrupt(js, "scoreboards not initialized");
|
||||
if (argc > 0 && JS_IsFunction(argv[0])) {
|
||||
g_scoreboard_js = js;
|
||||
JS_FreeValue(js, g_boards_list_callback);
|
||||
@@ -138,13 +138,13 @@ JSC_CCALL(scoreboards_getScoreboards,
|
||||
)
|
||||
|
||||
JSC_CCALL(scoreboards_freeBoardsList,
|
||||
if (!pd_scoreboards) return JS_ThrowInternalError(js, "scoreboards not initialized");
|
||||
if (!pd_scoreboards) return JS_RaiseDisrupt(js, "scoreboards not initialized");
|
||||
// Managed by Playdate after callback
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_SCALL(scoreboards_getScores,
|
||||
if (!pd_scoreboards) return JS_ThrowInternalError(js, "scoreboards not initialized");
|
||||
if (!pd_scoreboards) return JS_RaiseDisrupt(js, "scoreboards not initialized");
|
||||
if (argc > 1 && JS_IsFunction(argv[1])) {
|
||||
g_scoreboard_js = js;
|
||||
JS_FreeValue(js, g_scores_callback);
|
||||
@@ -154,7 +154,7 @@ JSC_SCALL(scoreboards_getScores,
|
||||
)
|
||||
|
||||
JSC_CCALL(scoreboards_freeScoresList,
|
||||
if (!pd_scoreboards) return JS_ThrowInternalError(js, "scoreboards not initialized");
|
||||
if (!pd_scoreboards) return JS_RaiseDisrupt(js, "scoreboards not initialized");
|
||||
// Managed by Playdate after callback
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
@@ -28,77 +28,77 @@ static SoundChannel* js2channel(JSContext *js, JSValueConst val) {
|
||||
|
||||
// --- Global ---
|
||||
JSC_CCALL(sound_getCurrentTime,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewInt64(js, pd_sound->getCurrentTime());
|
||||
)
|
||||
JSC_CCALL(sound_getDefaultChannel,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
SoundChannel *ch = pd_sound->getDefaultChannel();
|
||||
return ch ? JS_NewInt64(js, (int64_t)(intptr_t)ch) : JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_addChannel,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewBool(js, pd_sound->addChannel(js2channel(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_removeChannel,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewBool(js, pd_sound->removeChannel(js2channel(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_setOutputsActive,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->setOutputsActive(JS_ToBool(js, argv[0]), JS_ToBool(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_getError,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
const char *err = pd_sound->getError();
|
||||
return err ? JS_NewString(js, err) : JS_NULL;
|
||||
)
|
||||
|
||||
// --- FilePlayer ---
|
||||
JSC_CCALL(sound_newFilePlayer,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
FilePlayer *p = pd_sound->fileplayer->newPlayer();
|
||||
return p ? JS_NewInt64(js, (int64_t)(intptr_t)p) : JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_freeFilePlayer,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
FilePlayer *p = js2fileplayer(js, argv[0]);
|
||||
if (p) pd_sound->fileplayer->freePlayer(p);
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_SCALL(sound_loadIntoFilePlayer,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
FilePlayer *p = js2fileplayer(js, argv[0]);
|
||||
ret = JS_NewBool(js, pd_sound->fileplayer->loadIntoPlayer(p, str));
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerPlay,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
FilePlayer *p = js2fileplayer(js, argv[0]);
|
||||
int repeat = argc > 1 ? (int)js2number(js, argv[1]) : 1;
|
||||
return JS_NewBool(js, pd_sound->fileplayer->play(p, repeat));
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerIsPlaying,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewBool(js, pd_sound->fileplayer->isPlaying(js2fileplayer(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerPause,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->fileplayer->pause(js2fileplayer(js, argv[0]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerStop,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->fileplayer->stop(js2fileplayer(js, argv[0]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerSetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->fileplayer->setVolume(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerGetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
float l, r; pd_sound->fileplayer->getVolume(js2fileplayer(js, argv[0]), &l, &r);
|
||||
JSValue obj = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js, obj, "left", JS_NewFloat64(js, l));
|
||||
@@ -106,109 +106,109 @@ JSC_CCALL(sound_filePlayerGetVolume,
|
||||
return obj;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerGetLength,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewFloat64(js, pd_sound->fileplayer->getLength(js2fileplayer(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerSetOffset,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->fileplayer->setOffset(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerGetOffset,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewFloat64(js, pd_sound->fileplayer->getOffset(js2fileplayer(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerSetRate,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->fileplayer->setRate(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerGetRate,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewFloat64(js, pd_sound->fileplayer->getRate(js2fileplayer(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerSetLoopRange,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->fileplayer->setLoopRange(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerDidUnderrun,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewBool(js, pd_sound->fileplayer->didUnderrun(js2fileplayer(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerSetStopOnUnderrun,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->fileplayer->setStopOnUnderrun(js2fileplayer(js, argv[0]), JS_ToBool(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_filePlayerSetBufferLength,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->fileplayer->setBufferLength(js2fileplayer(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
// --- Sample ---
|
||||
JSC_SCALL(sound_loadSample,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
AudioSample *s = pd_sound->sample->load(str);
|
||||
ret = s ? JS_NewInt64(js, (int64_t)(intptr_t)s) : JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_freeSample,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
AudioSample *s = js2sample(js, argv[0]);
|
||||
if (s) pd_sound->sample->freeSample(s);
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_getSampleLength,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewFloat64(js, pd_sound->sample->getLength(js2sample(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_newSampleBuffer,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
AudioSample *s = pd_sound->sample->newSampleBuffer((int)js2number(js, argv[0]));
|
||||
return s ? JS_NewInt64(js, (int64_t)(intptr_t)s) : JS_NULL;
|
||||
)
|
||||
|
||||
// --- SamplePlayer ---
|
||||
JSC_CCALL(sound_newSamplePlayer,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
SamplePlayer *p = pd_sound->sampleplayer->newPlayer();
|
||||
return p ? JS_NewInt64(js, (int64_t)(intptr_t)p) : JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_freeSamplePlayer,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
SamplePlayer *p = js2sampleplayer(js, argv[0]);
|
||||
if (p) pd_sound->sampleplayer->freePlayer(p);
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerSetSample,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->sampleplayer->setSample(js2sampleplayer(js, argv[0]), js2sample(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerPlay,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
SamplePlayer *p = js2sampleplayer(js, argv[0]);
|
||||
int repeat = argc > 1 ? (int)js2number(js, argv[1]) : 1;
|
||||
float rate = argc > 2 ? (float)js2number(js, argv[2]) : 1.0f;
|
||||
return JS_NewBool(js, pd_sound->sampleplayer->play(p, repeat, rate));
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerIsPlaying,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewBool(js, pd_sound->sampleplayer->isPlaying(js2sampleplayer(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerStop,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->sampleplayer->stop(js2sampleplayer(js, argv[0]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerSetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->sampleplayer->setVolume(js2sampleplayer(js, argv[0]), (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerGetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
float l, r; pd_sound->sampleplayer->getVolume(js2sampleplayer(js, argv[0]), &l, &r);
|
||||
JSValue obj = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js, obj, "left", JS_NewFloat64(js, l));
|
||||
@@ -216,82 +216,82 @@ JSC_CCALL(sound_samplePlayerGetVolume,
|
||||
return obj;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerGetLength,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewFloat64(js, pd_sound->sampleplayer->getLength(js2sampleplayer(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerSetOffset,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->sampleplayer->setOffset(js2sampleplayer(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerGetOffset,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewFloat64(js, pd_sound->sampleplayer->getOffset(js2sampleplayer(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerSetRate,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->sampleplayer->setRate(js2sampleplayer(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerGetRate,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewFloat64(js, pd_sound->sampleplayer->getRate(js2sampleplayer(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerSetPlayRange,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->sampleplayer->setPlayRange(js2sampleplayer(js, argv[0]), (int)js2number(js, argv[1]), (int)js2number(js, argv[2]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_samplePlayerSetPaused,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->sampleplayer->setPaused(js2sampleplayer(js, argv[0]), JS_ToBool(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
// --- Synth ---
|
||||
JSC_CCALL(sound_newSynth,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
PDSynth *s = pd_sound->synth->newSynth();
|
||||
return s ? JS_NewInt64(js, (int64_t)(intptr_t)s) : JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_freeSynth,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
PDSynth *s = js2synth(js, argv[0]);
|
||||
if (s) pd_sound->synth->freeSynth(s);
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthSetWaveform,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->synth->setWaveform(js2synth(js, argv[0]), (SoundWaveform)(int)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthSetAttackTime,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->synth->setAttackTime(js2synth(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthSetDecayTime,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->synth->setDecayTime(js2synth(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthSetSustainLevel,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->synth->setSustainLevel(js2synth(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthSetReleaseTime,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->synth->setReleaseTime(js2synth(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthSetTranspose,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->synth->setTranspose(js2synth(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthPlayNote,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
PDSynth *s = js2synth(js, argv[0]);
|
||||
float freq = (float)js2number(js, argv[1]);
|
||||
float vel = argc > 2 ? (float)js2number(js, argv[2]) : 1.0f;
|
||||
@@ -301,7 +301,7 @@ JSC_CCALL(sound_synthPlayNote,
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthPlayMIDINote,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
PDSynth *s = js2synth(js, argv[0]);
|
||||
MIDINote note = (MIDINote)js2number(js, argv[1]);
|
||||
float vel = argc > 2 ? (float)js2number(js, argv[2]) : 1.0f;
|
||||
@@ -311,22 +311,22 @@ JSC_CCALL(sound_synthPlayMIDINote,
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthNoteOff,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->synth->noteOff(js2synth(js, argv[0]), argc > 1 ? (uint32_t)js2number(js, argv[1]) : 0);
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthStop,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->synth->stop(js2synth(js, argv[0]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthSetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->synth->setVolume(js2synth(js, argv[0]), (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_synthGetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
float l, r; pd_sound->synth->getVolume(js2synth(js, argv[0]), &l, &r);
|
||||
JSValue obj = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js, obj, "left", JS_NewFloat64(js, l));
|
||||
@@ -334,41 +334,41 @@ JSC_CCALL(sound_synthGetVolume,
|
||||
return obj;
|
||||
)
|
||||
JSC_CCALL(sound_synthIsPlaying,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewBool(js, pd_sound->synth->isPlaying(js2synth(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_synthGetParameterCount,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewInt32(js, pd_sound->synth->getParameterCount(js2synth(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_synthSetParameter,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewBool(js, pd_sound->synth->setParameter(js2synth(js, argv[0]), (int)js2number(js, argv[1]), (float)js2number(js, argv[2])));
|
||||
)
|
||||
|
||||
// --- Channel ---
|
||||
JSC_CCALL(sound_newChannel,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
SoundChannel *ch = pd_sound->channel->newChannel();
|
||||
return ch ? JS_NewInt64(js, (int64_t)(intptr_t)ch) : JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_freeChannel,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
SoundChannel *ch = js2channel(js, argv[0]);
|
||||
if (ch) pd_sound->channel->freeChannel(ch);
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_channelSetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->channel->setVolume(js2channel(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
JSC_CCALL(sound_channelGetVolume,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
return JS_NewFloat64(js, pd_sound->channel->getVolume(js2channel(js, argv[0])));
|
||||
)
|
||||
JSC_CCALL(sound_channelSetPan,
|
||||
if (!pd_sound) return JS_ThrowInternalError(js, "sound not initialized");
|
||||
if (!pd_sound) return JS_RaiseDisrupt(js, "sound not initialized");
|
||||
pd_sound->channel->setPan(js2channel(js, argv[0]), (float)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
@@ -21,76 +21,76 @@ static LCDBitmap* js2bitmap(JSContext *js, JSValueConst val) {
|
||||
// --- Sprite Functions ---
|
||||
|
||||
JSC_CCALL(sprite_setAlwaysRedraw,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
pd_sprite->setAlwaysRedraw(JS_ToBool(js, argv[0]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_drawSprites,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
pd_sprite->drawSprites();
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_updateAndDrawSprites,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
pd_sprite->updateAndDrawSprites();
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_newSprite,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = pd_sprite->newSprite();
|
||||
if (!s) return JS_ThrowInternalError(js, "failed to create sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "failed to create sprite");
|
||||
return JS_NewInt64(js, (int64_t)(intptr_t)s);
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_freeSprite,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (s) pd_sprite->freeSprite(s);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_copy,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
LCDSprite *copy = pd_sprite->copy(s);
|
||||
return copy ? JS_NewInt64(js, (int64_t)(intptr_t)copy) : JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_addSprite,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->addSprite(s);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_removeSprite,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->removeSprite(s);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_removeAllSprites,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
pd_sprite->removeAllSprites();
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getSpriteCount,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
return JS_NewInt32(js, pd_sprite->getSpriteCount());
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setBounds,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
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);
|
||||
@@ -98,9 +98,9 @@ JSC_CCALL(sprite_setBounds,
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getBounds,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
PDRect b = pd_sprite->getBounds(s);
|
||||
JSValue obj = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, b.x));
|
||||
@@ -111,143 +111,143 @@ JSC_CCALL(sprite_getBounds,
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_moveTo,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->moveTo(s, (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_moveBy,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->moveBy(s, (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setImage,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
LCDBitmap *img = js2bitmap(js, argv[1]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
LCDBitmapFlip flip = argc > 2 ? (LCDBitmapFlip)(int)js2number(js, argv[2]) : kBitmapUnflipped;
|
||||
pd_sprite->setImage(s, img, flip);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getImage,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
LCDBitmap *img = pd_sprite->getImage(s);
|
||||
return img ? JS_NewInt64(js, (int64_t)(intptr_t)img) : JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setSize,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->setSize(s, (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setZIndex,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->setZIndex(s, (int16_t)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getZIndex,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
return JS_NewInt32(js, pd_sprite->getZIndex(s));
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setDrawMode,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->setDrawMode(s, (LCDBitmapDrawMode)(int)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setImageFlip,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->setImageFlip(s, (LCDBitmapFlip)(int)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getImageFlip,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
return JS_NewInt32(js, pd_sprite->getImageFlip(s));
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setVisible,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->setVisible(s, JS_ToBool(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_isVisible,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
return JS_NewBool(js, pd_sprite->isVisible(s));
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setOpaque,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->setOpaque(s, JS_ToBool(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_markDirty,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->markDirty(s);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setTag,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->setTag(s, (uint8_t)js2number(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getTag,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
return JS_NewInt32(js, pd_sprite->getTag(s));
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setIgnoresDrawOffset,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->setIgnoresDrawOffset(s, JS_ToBool(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getPosition,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
float x, y;
|
||||
pd_sprite->getPosition(s, &x, &y);
|
||||
JSValue obj = JS_NewObject(js);
|
||||
@@ -257,17 +257,17 @@ JSC_CCALL(sprite_getPosition,
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setCenter,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->setCenter(s, (float)js2number(js, argv[1]), (float)js2number(js, argv[2]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getCenter,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
float x, y;
|
||||
pd_sprite->getCenter(s, &x, &y);
|
||||
JSValue obj = JS_NewObject(js);
|
||||
@@ -279,15 +279,15 @@ JSC_CCALL(sprite_getCenter,
|
||||
// --- Collision Functions ---
|
||||
|
||||
JSC_CCALL(sprite_resetCollisionWorld,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
pd_sprite->resetCollisionWorld();
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setCollideRect,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
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);
|
||||
@@ -295,9 +295,9 @@ JSC_CCALL(sprite_setCollideRect,
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_getCollideRect,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
PDRect r = pd_sprite->getCollideRect(s);
|
||||
JSValue obj = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, r.x));
|
||||
@@ -308,40 +308,40 @@ JSC_CCALL(sprite_getCollideRect,
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_clearCollideRect,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->clearCollideRect(s);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setCollisionsEnabled,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->setCollisionsEnabled(s, JS_ToBool(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_collisionsEnabled,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
return JS_NewBool(js, pd_sprite->collisionsEnabled(s));
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_setUpdatesEnabled,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
pd_sprite->setUpdatesEnabled(s, JS_ToBool(js, argv[1]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sprite_updatesEnabled,
|
||||
if (!pd_sprite) return JS_ThrowInternalError(js, "sprite not initialized");
|
||||
if (!pd_sprite) return JS_RaiseDisrupt(js, "sprite not initialized");
|
||||
LCDSprite *s = js2sprite(js, argv[0]);
|
||||
if (!s) return JS_ThrowTypeError(js, "invalid sprite");
|
||||
if (!s) return JS_RaiseDisrupt(js, "invalid sprite");
|
||||
return JS_NewBool(js, pd_sprite->updatesEnabled(s));
|
||||
)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// --- System Functions ---
|
||||
|
||||
JSC_CCALL(sys_logToConsole,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
const char *str = JS_ToCString(js, argv[0]);
|
||||
if (str) {
|
||||
pd_sys->logToConsole("%s", str);
|
||||
@@ -18,7 +18,7 @@ JSC_CCALL(sys_logToConsole,
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_error,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
const char *str = JS_ToCString(js, argv[0]);
|
||||
if (str) {
|
||||
pd_sys->error("%s", str);
|
||||
@@ -28,18 +28,18 @@ JSC_CCALL(sys_error,
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getLanguage,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
PDLanguage lang = pd_sys->getLanguage();
|
||||
return JS_NewInt32(js, lang);
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getCurrentTimeMilliseconds,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
return JS_NewInt64(js, pd_sys->getCurrentTimeMilliseconds());
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getSecondsSinceEpoch,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
unsigned int ms = 0;
|
||||
unsigned int secs = pd_sys->getSecondsSinceEpoch(&ms);
|
||||
JSValue obj = JS_NewObject(js);
|
||||
@@ -49,7 +49,7 @@ JSC_CCALL(sys_getSecondsSinceEpoch,
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_drawFPS,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
int x = (int)js2number(js, argv[0]);
|
||||
int y = (int)js2number(js, argv[1]);
|
||||
pd_sys->drawFPS(x, y);
|
||||
@@ -57,7 +57,7 @@ JSC_CCALL(sys_drawFPS,
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getButtonState,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
PDButtons current, pushed, released;
|
||||
pd_sys->getButtonState(¤t, &pushed, &released);
|
||||
JSValue obj = JS_NewObject(js);
|
||||
@@ -68,14 +68,14 @@ JSC_CCALL(sys_getButtonState,
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_setPeripheralsEnabled,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
PDPeripherals mask = (PDPeripherals)(int)js2number(js, argv[0]);
|
||||
pd_sys->setPeripheralsEnabled(mask);
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getAccelerometer,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
float x, y, z;
|
||||
pd_sys->getAccelerometer(&x, &y, &z);
|
||||
JSValue obj = JS_NewObject(js);
|
||||
@@ -86,76 +86,76 @@ JSC_CCALL(sys_getAccelerometer,
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getCrankChange,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
return JS_NewFloat64(js, pd_sys->getCrankChange());
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getCrankAngle,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
return JS_NewFloat64(js, pd_sys->getCrankAngle());
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_isCrankDocked,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
return JS_NewBool(js, pd_sys->isCrankDocked());
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_setCrankSoundsDisabled,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
int flag = JS_ToBool(js, argv[0]);
|
||||
int prev = pd_sys->setCrankSoundsDisabled(flag);
|
||||
return JS_NewBool(js, prev);
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getFlipped,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
return JS_NewBool(js, pd_sys->getFlipped());
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_setAutoLockDisabled,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
pd_sys->setAutoLockDisabled(JS_ToBool(js, argv[0]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getReduceFlashing,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
return JS_NewBool(js, pd_sys->getReduceFlashing());
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getElapsedTime,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
return JS_NewFloat64(js, pd_sys->getElapsedTime());
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_resetElapsedTime,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
pd_sys->resetElapsedTime();
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getBatteryPercentage,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
return JS_NewFloat64(js, pd_sys->getBatteryPercentage());
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getBatteryVoltage,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
return JS_NewFloat64(js, pd_sys->getBatteryVoltage());
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getTimezoneOffset,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
return JS_NewInt32(js, pd_sys->getTimezoneOffset());
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_shouldDisplay24HourTime,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
return JS_NewBool(js, pd_sys->shouldDisplay24HourTime());
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_convertEpochToDateTime,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
uint32_t epoch = (uint32_t)js2number(js, argv[0]);
|
||||
struct PDDateTime dt;
|
||||
pd_sys->convertEpochToDateTime(epoch, &dt);
|
||||
@@ -171,7 +171,7 @@ JSC_CCALL(sys_convertEpochToDateTime,
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_convertDateTimeToEpoch,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
struct PDDateTime dt = {0};
|
||||
dt.year = (uint16_t)js2number(js, JS_GetPropertyStr(js, argv[0], "year"));
|
||||
dt.month = (uint8_t)js2number(js, JS_GetPropertyStr(js, argv[0], "month"));
|
||||
@@ -183,24 +183,24 @@ JSC_CCALL(sys_convertDateTimeToEpoch,
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_clearICache,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
pd_sys->clearICache();
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_delay,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
pd_sys->delay((uint32_t)js2number(js, argv[0]));
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
JSC_SCALL(sys_restartGame,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
pd_sys->restartGame(str);
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getLaunchArgs,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
const char *path = NULL;
|
||||
const char *args = pd_sys->getLaunchArgs(&path);
|
||||
JSValue obj = JS_NewObject(js);
|
||||
@@ -210,7 +210,7 @@ JSC_CCALL(sys_getLaunchArgs,
|
||||
)
|
||||
|
||||
JSC_CCALL(sys_getSystemInfo,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
const struct PDInfo *info = pd_sys->getSystemInfo();
|
||||
if (!info) return JS_NULL;
|
||||
JSValue obj = JS_NewObject(js);
|
||||
@@ -222,7 +222,7 @@ JSC_CCALL(sys_getSystemInfo,
|
||||
// --- Menu Functions ---
|
||||
|
||||
JSC_CCALL(sys_removeAllMenuItems,
|
||||
if (!pd_sys) return JS_ThrowInternalError(js, "system not initialized");
|
||||
if (!pd_sys) return JS_RaiseDisrupt(js, "system not initialized");
|
||||
pd_sys->removeAllMenuItems();
|
||||
return JS_NULL;
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user