예제 #1
0
파일: FskSSL.c 프로젝트: afrog33k/kinomajs
FskErr
FskSSLRead(void *a, void *buf, int *bufLen)
{
	FskSSL *fssl = a;
	FskErr err = kFskErrNone;
	int len = *bufLen, nread;

	if (fssl->skt == NULL)
		return kFskErrOperationFailed;

	xsBeginHost(fssl->vm->the);
	xsTry {
		xsCall1_noResult(fssl->socket, xsID("attachData"), xsHostData(fssl->skt));
		xsResult = xsCall2(fssl->ssl, xsID("read"), fssl->socket, xsInteger(len));
		if (xsTest(xsResult)) {
			nread = xsToInteger(xsGet(xsResult, xsID("length")));
			if (nread > len)
				nread = len;
			FskMemCopy(buf, xsGetHostData(xsResult), nread);
			xsCall0_noResult(xsResult, xsID("free"));
			*bufLen = nread;
			err = nread == 0 ? kFskErrNoData: kFskErrNone;
		}
		else
			err = kFskErrConnectionClosed;
	} xsCatch {
		if (xsHas(xsException, xsID("code")))
			err = xsToInteger(xsGet(xsException, xsID("code")));
		if (err == kFskErrNone)
			err = kFskErrOperationFailed;
	}
	xsEndHost(fssl->vm->the);
	return err;
}
예제 #2
0
파일: arith_ed.c 프로젝트: basuke/kinomajs
void
xs_ed_init(xsMachine *the)
{
	ed_t *ed;
	mod_t *mod;	/* mod_t* */
	void *d;	/* kcl_int_t* */
	kcl_err_t err;

	if ((ed = crypt_malloc(sizeof(ed_t))) == NULL)
		kcl_throw_error(the, KCL_ERR_NOMEM);
	if ((err = kcl_ed_alloc(&ed->ctx)) != KCL_ERR_NONE) {
		crypt_free(ed);
		kcl_throw_error(the, err);
	}
	xsResult = xsGet(xsThis, xsID("mod"));
	mod = xsGetHostData(xsResult);
	xsResult = xsGet(xsThis, xsID("d"));
	d = xsGetHostData(xsResult);
	kcl_ed_init(ed->ctx, mod->ctx, d);

	ed->id_x = xsID("x");
	ed->id_y = xsID("y");
	ed->proto_int = xsGet(xsThis, xsID("_proto_int"));
	ed->proto_ecp = xsGet(xsThis, xsID("_proto_ecp"));
	xsSetHostData(xsThis, ed);
}
예제 #3
0
파일: gpio.c 프로젝트: kouis3940/kinomajs
void xs_gpio_init(xsMachine* the)
{
    FskErr err;
    FskGPIO gpio;
    SInt32 pin = 0;
	GPIOdirection dir;
    char *pinName = NULL;

    xsVars(1);

    if ((gpio = xsGetHostData(xsThis)))
        xsThrowDiagnosticIfFskErr(kFskErrOperationFailed, "Digital pin %d already initialized.", (int)gpio->pinNum);

    dir = stringToDirection(the, xsToString(xsGet(xsThis, xsID("_direction"))), gpio);

    xsVar(0) = xsGet(xsThis, xsID("_pin"));
    if (xsStringType == xsTypeOf(xsVar(0)))
        pinName = xsToString(xsVar(0));
    else
        pin = xsToInteger(xsVar(0));

    err = FskGPIONew(&gpio, pin, pinName, dir);
    xsThrowDiagnosticIfFskErr(err, "Digital pin %d initialization failed with error %s.", pin, FskInstrumentationGetErrorString(err));

    xsSetHostData(xsThis, gpio);
}
예제 #4
0
void KPR_message_setRequestCertificate(xsMachine* the)
{
	KprMessage self = xsGetHostData(xsThis);
	FskSocketCertificateRecord* certs = NULL;
	FskSocketCertificateRecord certsRecord = {
		NULL, 0,
		NULL,
		NULL,
		NULL, 0,
	};
	if (xsIsInstanceOf(xsArg(0), xsObjectPrototype)) {
		certs = &certsRecord;
		if (xsHas(xsArg(0), xsID("certificates"))) {
			certs->certificates = (void*)xsToString(xsGet(xsArg(0), xsID("certificates")));
			certs->certificatesSize = FskStrLen(certs->certificates);
		}
		if (xsHas(xsArg(0), xsID("policies"))) {
			certs->policies = xsToString(xsGet(xsArg(0), xsID("policies")));
		}
		if (xsHas(xsArg(0), xsID("key"))) {
			certs->key = (void*)xsToString(xsGet(xsArg(0), xsID("key")));
			certs->keySize = FskStrLen(certs->key);
		}
	}
	else { // compatibility
		certs = &certsRecord;
		if (xsTest(xsArg(0))) {
			certs->certificates = xsGetHostData(xsArg(0));
			certs->certificatesSize = xsToInteger(xsGet(xsArg(0), xsID_length));
		}
		if (xsTest(xsArg(1)))
			certs->policies = xsToString(xsArg(1));
	}
	xsThrowIfFskErr(KprMessageSetRequestCertificate(self, certs));
}
예제 #5
0
void
xs_mod_init(xsMachine *the)
{
	mod_t *mod;
	UInt32 options = xsToInteger(xsArgc) > 0 && xsTypeOf(xsArg(0)) == xsIntegerType ? xsToInteger(xsArg(0)): 0;
	FskErr ferr;

	if ((ferr = FskMemPtrNew(sizeof(mod_t), (FskMemPtr *)&mod)) != kFskErrNone)
		cryptThrowFSK(ferr);
	if ((ferr = FskMemPtrNew(sizeof(bn_mod_t), (FskMemPtr *)&mod->mod_data)) != kFskErrNone) {
		FskMemPtrDispose(mod);
		cryptThrowFSK(ferr);
	}

	mod->_mod_code = &modFuncs;

	xsResult = xsGet(xsThis, xsID("z"));	/* must exist */
	if (!xsIsInstanceOf(xsResult, xsGet(xsGet(xsGlobal, xsID("Arith")), xsID("z"))) || (mod->z = xsGetHostData(xsResult)) == NULL)
		cryptThrow("kCryptTypeError");

	xsResult = xsGet(xsThis, xsID("m"));	/* must exist */
	if (!xsIsInstanceOf(xsResult, mod->z->z_protoInteger) || (mod->m = xsGetHostData(xsResult)) == NULL)
		nanError();

	bn_mod_init(mod->mod_data, mod->z->z_data, mod->m->cint_data, options);

	xsSetHostData(xsThis, mod);
}
예제 #6
0
void KPR_canvasPattern_setStyle(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsArg(0));
	UInt32 repetition = kFskCanvas2dPatternRepeat;
	FskConstBitmap bitmap = NULL;
	Boolean owned = false;
	xsVars(1);
	xsVar(0) = xsGet(xsThis, xsID("repetition"));
	if (xsTest(xsVar(0))) {
		xsStringValue it = xsToString(xsVar(0));
		if (!FskStrCompare(it, "no-repeat")) repetition = kFskCanvas2dPatternRepeatNone;
		else if (!FskStrCompare(it, "repeat-x")) repetition = kFskCanvas2dPatternRepeatX;
		else if (!FskStrCompare(it, "repeat-y")) repetition = kFskCanvas2dPatternRepeatY;
		else if (!FskStrCompare(it, "repeat")) repetition = kFskCanvas2dPatternRepeat;
		else xsError(kFskErrInvalidParameter);
	}
	xsVar(0) = xsGet(xsThis, xsID("image"));
	if (xsIsInstanceOf(xsVar(0), xsGet(xsGet(xsGlobal, xsID_KPR), xsID_texture))) {
		KprTexture texture = xsGetHostData(xsVar(0));
		bitmap = KprTextureGetBitmap(texture, NULL, &owned);
	}
	else {
		KprContent content = xsGetHostData(xsVar(0));
		bitmap = (*content->dispatch->getBitmap)(content, NULL, &owned);
	}
	if (!bitmap)
		xsError(kFskErrInvalidParameter);
	if (xsTest(xsArg(1)))
		FskCanvas2dSetStrokeStylePattern(ctx, repetition, bitmap);
	else
		FskCanvas2dSetFillStylePattern(ctx, repetition, bitmap);
	if (!owned)
		FskBitmapDispose((FskBitmap)bitmap);
}
예제 #7
0
static void KprPromiseTargetComplete(KprMessage message, void* it)
{
	KprPromiseTarget self = it;
	xsBeginHost(self->the);
	xsVars(3);
	xsVar(0) = xsAccess(self->resolve);
	xsVar(1) = xsAccess(self->reject);
	if (message->error) {
		xsVar(2) = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID_KPR), xsID_message));
		xsSetHostData(xsVar(2), message);
		FskInstrumentedItemSendMessageDebug(message, kprInstrumentedMessageConstruct, message);
		message->usage++; // host
		(void)xsCallFunction1(xsVar(1), xsUndefined, xsVar(2));
	}
	else {
		if (message->stream)
			KprMessageScriptTargetGet(message, the, &xsVar(2));
		else {
			xsVar(2) = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID_KPR), xsID_message));
			xsSetHostData(xsVar(2), message);
			FskInstrumentedItemSendMessageDebug(message, kprInstrumentedMessageConstruct, message);
			message->usage++; // host
		}
		(void)xsCallFunction1(xsVar(0), xsUndefined, xsVar(2));
	}
	xsEndHost(self->the);
}
예제 #8
0
void KPR_canvasRadialGradient_setStyle(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsArg(0));
	xsNumberValue x0 = xsToNumber(xsGet(xsThis, xsID("x0")));
	xsNumberValue y0 = xsToNumber(xsGet(xsThis, xsID("y0")));
	xsNumberValue r0 = xsToNumber(xsGet(xsThis, xsID("r0")));
	xsNumberValue x1 = xsToNumber(xsGet(xsThis, xsID("x1")));
	xsNumberValue y1 = xsToNumber(xsGet(xsThis, xsID("y1")));
	xsNumberValue r1 = xsToNumber(xsGet(xsThis, xsID("r1")));
	UInt32 c, i;
	FskCanvas2dGradientStop stops[kCanvas2DMaxGradientStops];
	xsVars(2);
	xsVar(0) = xsGet(xsThis, xsID("stops"));
	c = xsToInteger(xsGet(xsVar(0), xsID("length")));
	if (c > kCanvas2DMaxGradientStops) c = kCanvas2DMaxGradientStops;
	for (i = 0; i < c; i++) {
		xsVar(1) = xsGetAt(xsVar(0), xsInteger(i));
		stops[i].offset = xsToNumber(xsGet(xsVar(1), xsID("offset")));
		xsVar(1) = xsGet(xsVar(1), xsID("color"));
		if (!KprParseColor(the, xsToString(xsVar(1)), &(stops[i].color)))
			return;
	}
	if (xsTest(xsArg(1)))
		FskCanvas2dSetStrokeStyleRadialGradient(ctx, x0, y0, r0, x1, y1, r1, c, stops);
	else
		FskCanvas2dSetFillStyleRadialGradient(ctx, x0, y0, r0, x1, y1, r1, c, stops);
}
예제 #9
0
void Library_cacheQuery(xsMachine* the)
{
    KprLibraryServer self = gLibraryServer;
    UInt32 index;
    KprLibraryQuery query;
    FskMutexAcquire(self->queryMutex);
    index = self->queryIndex % kQueryCount;
    query = self->queries[index];
    if (query) {
        KprLibraryQueryDispose(query);
        self->queries[index] = NULL;
    }
    KprLibraryQueryNew(&query);
    FskInstrumentedItemSetOwner(query, self);
    xsEnterSandbox();
    query->index = self->queryIndex;
    query->info = FskStrDoCopy(xsToString(xsGet(xsArg(0), xsID("info"))));
    query->kind = xsToInteger(xsGet(xsArg(0), xsID("kind")));
    query->mime = FskStrDoCopy(xsToString(xsGet(xsArg(0), xsID("mime"))));
    query->url = FskStrDoCopy(xsToString(xsGet(xsArg(0), xsID("url"))));
    xsResult = xsGet(xsArg(0), xsID("authorization"));
    if (xsTest(xsResult))
        query->authorization = FskStrDoCopy(xsToString(xsResult));
    xsLeaveSandbox();
    self->queries[index] = query;
    xsResult = xsInteger(self->queryIndex);
    self->queryIndex++;
    FskMutexRelease(self->queryMutex);
}
예제 #10
0
// image data
void KPR_canvasRenderingContext2D_cloneImageData(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	FskCanvas2dImageData data = xsGetHostData(xsArg(0));
	data = FskCanvas2dCloneImageData(ctx, data);
	xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("imageData")));
	xsSetHostData(xsResult, data);
}
예제 #11
0
파일: xsInfoset.c 프로젝트: basuke/kinomajs
void scanStopTag(void *data, const char *name)
{
	Scanner* self = data;
	xsMachine* the = self->the;
	scanText(data);
	xsArrayCacheEnd(xsVar(CHILDREN));
	xsResult = xsGet(xsResult, xsID_parent);
	xsVar(CHILDREN) = xsGet(xsResult, xsID_children);
}
예제 #12
0
// pixel manipulation
void KPR_canvasRenderingContext2D_createImageData(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsNumberValue sw = xsToNumber(xsArg(0));
	xsNumberValue sh = xsToNumber(xsArg(1));
	FskCanvas2dImageData data = FskCanvas2dCreateImageData(ctx, sw, sh);
	xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("imageData")));
	xsSetHostData(xsResult, data);
}
예제 #13
0
// drawing images
void KPR_canvasRenderingContext2D_drawImage(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsIntegerValue c = xsToInteger(xsArgc);
	FskConstCanvas cnv = NULL;
	FskBitmap bitmap = NULL;
	Boolean owned = false;
	xsVars(1);
	if (xsIsInstanceOf(xsArg(0), xsGet(xsGet(xsGlobal, xsID_KPR), xsID_texture))) {
		KprTexture texture = xsGetHostData(xsArg(0));
		bitmap = KprTextureGetBitmap(texture, NULL, &owned);
	}
	else {
		KprContent content = xsGetHostData(xsArg(0));
		if (content->dispatch == &KprCanvasDispatchRecord)
			cnv = ((KprCanvas)content)->cnv;
		else
			bitmap = (*content->dispatch->getBitmap)(content, NULL, &owned);
	}
	if (!cnv && !bitmap)
		xsError(kFskErrInvalidParameter);
	if (c > 8) {
		xsNumberValue sx = xsToNumber(xsArg(1));
		xsNumberValue sy = xsToNumber(xsArg(2));
		xsNumberValue sw = xsToNumber(xsArg(3));
		xsNumberValue sh = xsToNumber(xsArg(4));
		xsNumberValue dx = xsToNumber(xsArg(5));
		xsNumberValue dy = xsToNumber(xsArg(6));
		xsNumberValue dw = xsToNumber(xsArg(7));
		xsNumberValue dh = xsToNumber(xsArg(8));
		if (cnv)
			FskCanvas2dDrawSubScaledCanvas2d(ctx, cnv, sx, sy, sw, sh, dx, dy, dw, dh);
		else
			FskCanvas2dDrawSubScaledBitmap(ctx, bitmap, sx, sy, sw, sh, dx, dy, dw, dh);
	}
	else if (c > 4) {
		xsNumberValue dx = xsToNumber(xsArg(1));
		xsNumberValue dy = xsToNumber(xsArg(2));
		xsNumberValue dw = xsToNumber(xsArg(3));
		xsNumberValue dh = xsToNumber(xsArg(4));
		if (cnv)
			FskCanvas2dDrawScaledCanvas2d(ctx, cnv, dx, dy, dw, dh);
		else
			FskCanvas2dDrawScaledBitmap(ctx, bitmap, dx, dy, dw, dh);
	}
	else {
		xsNumberValue dx = xsToNumber(xsArg(1));
		xsNumberValue dy = xsToNumber(xsArg(2));
		if (cnv)
			FskCanvas2dDrawCanvas2d(ctx, cnv, dx, dy);
		else
			FskCanvas2dDrawBitmap(ctx, bitmap, dx, dy);
	}
	if (!owned)
		FskBitmapDispose(bitmap);
}
예제 #14
0
파일: FskSSL.c 프로젝트: afrog33k/kinomajs
FskErr
FskSSLNew(void **fsslp, const char *host, int port, Boolean blocking, long flags, int priority)
{
	FskSSL *fssl;
	FskErr err;

	if ((err = FskMemPtrNewClear(sizeof(FskSSL), (FskMemPtr*)(void*)&fssl)) != kFskErrNone)
		return err;
	if ((err = newSSLVM(&fssl->vm)) != kFskErrNone) {
		FskMemPtrDispose(fssl);
		return err;
	}

	xsBeginHost(fssl->vm->the);
	xsTry {
		const char *prStr;
		xsVars(2);
		/* construct the options */
		xsVar(0) = xsNewInstanceOf(xsObjectPrototype);
		if (blocking)
			xsSet(xsVar(0), xsID("blocking"), xsTrue);
		if (flags & kConnectFlagsSynchronous)
			xsSet(xsVar(0), xsID("synchronous"), xsTrue);
		switch (priority) {
		default:
		case kFskNetSocketLowestPriority: prStr = "lowest"; break;
		case kFskNetSocketLowPriority: prStr = "low"; break;
		case kFskNetSocketMediumPriority: prStr = "medium"; break;
		case kFskNetSocketHighPriority: prStr = "high"; break;
		case kFskNetSocketHighestPriority: prStr = "highest"; break;
		}
		(void)xsSet(xsVar(0), xsID("priority"), xsString((xsStringValue)prStr));
		(void)xsSet(xsVar(0), xsID("raw"), xsTrue);
		xsVar(1) = xsNew3(xsGet(xsGlobal, xsID("Stream")), xsID("Socket"), xsString((xsStringValue)host), xsInteger(port), xsVar(0));
		fssl->socket = xsVar(1); xsRemember(fssl->socket);
		xsVar(1) = xsNew0(xsGet(xsGlobal, xsID("FskSSL")), xsID("Session"));
		fssl->ssl = xsVar(1); xsRemember(fssl->ssl);
	} xsCatch {
		if (xsHas(xsException, xsID("code")))
			err = xsToInteger(xsGet(xsException, xsID("code")));
		if (err == kFskErrNone)
			err = kFskErrOperationFailed;
	}
	xsEndHost(fssl->vm->the);

	if (err == kFskErrNone) {
		if (fsslp != NULL)
			*fsslp = fssl;
	}
	else {
		disposeSSLVM(fssl->vm);
		FskMemPtrDispose(fssl);
	}
	return err;
}
예제 #15
0
void
xs_z_init(xsMachine *the)
{
	z_t *z;
	char *err;

	if ((err = kcl_z_init(the, &z)) != NULL)
		cryptThrow(err);
	z->z_protoInteger = xsGet(xsGet(xsGlobal, xsID("Arith")), xsID("integer"));
	xsSetHostData(xsThis, z);
}
예제 #16
0
파일: xsInfoset.c 프로젝트: basuke/kinomajs
void parseAttributes(xsMachine* the)
{
	xsIntegerValue c, i;
	if (xsTest(xsVar(CHILDREN))) {
		c = xsToInteger(xsGet(xsVar(CHILDREN), xsID_length));
		for (i = 0; i < c; i++) {
			xsVar(CHILD) = xsGet(xsVar(CHILDREN), i);
			parseAttribute(the);
		}
	}
}
예제 #17
0
void KPR_canvas_getContext(xsMachine *the)
{
	KprCanvas self = xsGetHostData(xsThis);
	if (self->cnv) {
		FskCanvas2dContext ctx = FskCanvasGet2dContext(self->cnv);
		xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("canvasRenderingContext2D")));
		xsSetHostData(xsResult, ctx);
		xsSet(xsResult, xsID("canvas"), xsThis);
		KprContentInvalidate((KprContent)self);
	}
}
예제 #18
0
void KPR_canvasRenderingContext2D_measureText(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsStringValue text = xsToString(xsArg(0));
	UInt16* buffer;
	if (kFskErrNone == FskTextUTF8ToUnicode16NE((unsigned char*)text, FskStrLen(text), &buffer, NULL)) {
		xsNumberValue width = FskCanvas2dMeasureText(ctx, buffer);
		FskMemPtrDispose(buffer);
		xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("textMetrics")));
		xsSet(xsResult, xsID("width"), xsNumber(width));
	}
}
예제 #19
0
void KPR_host_clearAllBreakpoints(xsMachine* the)
{
#ifdef mxDebug
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	xsBeginHost(application->the);
	{
		(void)xsCall0(xsGet(xsGet(xsGlobal, xsID("xs")), xsID("debug")), xsID("clearAllBreakpoints"));
	}
	xsEndHost(application->the);
#endif
}
예제 #20
0
FskErr KprApplicationNew(KprApplication* it, char* url, char* id, Boolean breakOnStart, Boolean breakOnExceptions)
{
	KprCoordinatesRecord coordinates = { kprLeftRight, kprTopBottom, 0, 0, 0, 0, 0, 0 };
	xsAllocation allocation = {
		2 * 1024 * 1024,
		1024 * 1024,
		64 * 1024,
		8 * 1024,
		2048,
		16000,
		1993
	};
	FskErr err = kFskErrNone;
	KprApplication self;
	
	bailIfError(FskMemPtrNewClear(sizeof(KprApplicationRecord), it));
	self = *it;
	FskInstrumentedItemNew(self, NULL, &KprApplicationInstrumentation);
	self->dispatch = &KprApplicationDispatchRecord;
	self->flags = kprContainer | kprClip | kprVisible;
	KprContentInitialize((KprContent)self, &coordinates, NULL, NULL);
	bailIfError(KprURLMerge(gShell->url, url, &self->url));	
	if (id) {
		self->id = FskStrDoCopy(id);	
		bailIfNULL(self->id);
	}
	self->the = xsAliasMachine(&allocation, gShell->root, self->url, self);
	if (!self->the) 
		BAIL(kFskErrMemFull);
	FskInstrumentedItemSendMessageNormal(self, kprInstrumentedContentCreateMachine, self);
	xsBeginHost(self->the);
	xsResult = xsNewHostFunction(KPR_include, 1);
	xsSet(xsResult, xsID("uri"), xsString(self->url));
	xsNewHostProperty(xsGlobal, xsID("include"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsResult = xsNewHostFunction(KPR_require, 1);
	xsSet(xsResult, xsID("uri"), xsString(self->url));
	xsNewHostProperty(xsGlobal, xsID("require"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("application")));
	self->slot = xsResult;
	xsSetHostData(xsResult, self);
	(void)xsCall1(xsGet(xsGlobal, xsID("Object")), xsID("seal"), xsResult);
	xsNewHostProperty(xsGlobal, xsID("application"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsNewHostProperty(xsGlobal, xsID("shell"), xsNull, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	if (breakOnStart)
		xsDebugger();
    if (breakOnExceptions)
		(void)xsCall1(xsGet(xsGet(xsGlobal, xsID("xs")), xsID("debug")), xsID("setBreakOnException"), xsBoolean(breakOnExceptions));
	(void)xsCall1(xsGlobal, xsID("include"), xsString(self->url));
	xsEndHost(self->the);
	KprContentChainPrepend(&gShell->applicationChain, self, 0, NULL);
bail:
	return err;
}
예제 #21
0
void KPR_host_set_debugging(xsMachine* the)
{
#ifdef mxDebug
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	Boolean flag = xsToBoolean(xsArg(0));
	xsBeginHost(application->the);
	{
		(void)xsCall1(xsGet(xsGet(xsGlobal, xsID("xs")), xsID("debug")), xsID("setConnected"), xsBoolean(flag));
	}
	xsEndHost(application->the);
#endif
}
예제 #22
0
void KPR_host_setBreakpoint(xsMachine* the)
{
#ifdef mxDebug
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	xsStringValue file = xsToString(xsArg(0));
	xsStringValue line = xsToString(xsArg(1));
	xsBeginHost(application->the);
	{
		(void)xsCall2(xsGet(xsGet(xsGlobal, xsID("xs")), xsID("debug")), xsID("setBreakpoint"), xsString(file), xsString(line));
	}
	xsEndHost(application->the);
#endif
}
예제 #23
0
void KPR_host_get_debugging(xsMachine* the)
{
#ifdef mxDebug
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	Boolean result = false;
	xsBeginHost(application->the);
	{
		result = xsTest(xsCall0(xsGet(xsGet(xsGlobal, xsID("xs")), xsID("debug")), xsID("getConnected")));
	}
	xsEndHost(application->the);
	xsResult = xsBoolean(result);
#endif
}
예제 #24
0
void KPR_host_set_profiling(xsMachine* the)
{
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	Boolean flag = xsToBoolean(xsArg(0));
	xsBeginHost(application->the);
	{
		if (flag)
			(void)xsCall0(xsGet(xsGlobal, xsID("xs")), xsID("startProfiling"));
		else
			(void)xsCall0(xsGet(xsGlobal, xsID("xs")), xsID("stopProfiling"));
	}
	xsEndHost(application->the);
}
예제 #25
0
파일: i2c.c 프로젝트: dadongdong/kinomajs
void xs_i2c_init(xsMachine *the)
{
    xsI2C i2c = NULL;
    FskErr err;
    int address;
    int sdaPin = 0, clkPin = 0, sdaDev = 0, clkDev = 0;
	FskPinI2C pin = NULL;

    if (xsGetHostData(xsThis))
        xsThrowDiagnosticIfFskErr(kFskErrBadState, "I2C pin already initialized (SDA pin %d).", i2c->sdaPin);

    address = xsToInteger(xsGet(xsThis, xsID("address")));
    xsResult = xsGet(xsThis, xsID("bus"));
    if (xsUndefinedType == xsTypeOf(xsResult)) {
        sdaPin = xsToInteger(xsGet(xsThis, xsID("sda")));
        clkPin = xsToInteger(xsGet(xsThis, xsID("clock")));

		err = FskPinI2CNew(&pin, sdaPin, clkPin, kFskPinI2CNoBus);
    }
    else {
        sdaDev = xsToInteger(xsResult);
		err = FskPinI2CNew(&pin, 0, 0, sdaDev);
	}

    xsThrowDiagnosticIfFskErr(err, "I2C open failed %s (SDA pin %d, CLK pin %d).", FskInstrumentationGetErrorString(err), sdaPin, clkPin);

    err = FskMemPtrNewClear(sizeof(xsI2CRecord), &i2c);
    if (err) {
        FskPinI2CDispose(pin);
        xsError(err);
    }
    
    xsSetHostData(xsThis, i2c);

	i2c->pin = pin;
    i2c->sdaPin = sdaPin;
    i2c->clkPin = clkPin;
    i2c->sdaDev = sdaDev;
    i2c->clkDev = clkDev;
    i2c->address = (UInt8)address;
    i2c->bus = sdaDev;

#if SUPPORT_XS_DEBUG
    if (0 != sdaPin)
        snprintf(i2c->diagnosticID, sizeof(i2c->diagnosticID), "(Address 0x%x, SDA pin %d, CLK pin %d)", address, sdaPin, clkPin);
    else
        snprintf(i2c->diagnosticID, sizeof(i2c->diagnosticID), "(Address 0x%x, Bus %d)", address, sdaDev);
#endif
}
예제 #26
0
파일: kpr.c 프로젝트: basuke/kinomajs
xsBooleanValue fxFindModuleLoadAsDirectory(xsMachine* the, xsStringValue base, xsStringValue name, xsIndex* id)
{
	char node[1024];
	UInt32 nodeSize;
	xsStringValue slash;
	FskErr err;
	FskFileMapping map = NULL;
	xsBooleanValue result = 0;
	xsStringValue path = NULL;
	unsigned char* data;
	FskInt64 size;
	xsSlot slot;
	
	nodeSize = sizeof(node);
	FskStrNCopy(node, base, nodeSize);
	slash = FskStrRChr(node, '/');
	if (slash)
		*slash = 0;
	FskStrNCat(node, "/", nodeSize);
	FskStrNCat(node, name, nodeSize);
	if (FskStrTail(node, "/") != 0)
		FskStrNCat(node, "/", nodeSize);
	FskStrNCat(node, "package.json", nodeSize);
	err = KprURLToPath(node, &path);
	if (err == kFskErrNone) {
		err = FskFileMap(path, &data, &size, 0, &map);
		if (err == kFskErrNone) {
			xsTry {
				slot = xsNewInstanceOf(xsChunkPrototype);
				xsSetHostData(slot, data);
				xsSetHostDestructor(slot, NULL);
				xsSet(slot, xsID("length"), xsInteger(size));
				slot = xsCall1(xsGet(xsGlobal, xsID("JSON")), xsID("parse"), slot);
			}
			xsCatch {
				slot = xsUndefined;
			}
			if (xsTest(slot)) {
				slot = xsGet(slot, xsID("main"));
				if (xsTest(slot)) {
					FskStrNCopy(node, name, nodeSize);
					if (FskStrTail(node, "/") != 0)
						FskStrNCat(node, "/", nodeSize);
					FskStrNCat(node, xsToString(slot), nodeSize);
					if (fxFindModuleLoadAsFile(the, base, node, id))
						result = 1;
				}
			}
		}
예제 #27
0
void kpr2jsWriteFile(xsMachine* the)
{
    FILE* aFile = xsGetHostData(xsThis);
    int c = fprintf(aFile, "%s", xsToString(xsArg(0)));
    c += xsToInteger(xsGet(xsThis, xsID("charCount")));
    xsSet(xsThis, xsID("charCount"), xsInteger(c));
}
예제 #28
0
void KprMessageScriptTargetTransform(void* it, KprMessage message, xsMachine* machine)
{
	KprMessageScriptTarget self = it;
	if (message->error) return;
	xsBeginHostSandboxCode(machine, NULL);
	{
		xsVars(2);
		{
			xsTry {
				void* data;
				UInt32 size; 
				KprMessageGetResponseBody(message, &data, &size);
				if (data && size) {
					xsIndex id = xsID(self->name);
					if (xsHas(xsGlobal, id)) {
						xsVar(0) = xsGet(xsGlobal, id);
						xsVar(1) = xsNewInstanceOf(xsChunkPrototype);
						xsSetHostData(xsVar(1), data);
						xsSetHostDestructor(xsVar(1) , NULL);
						xsSet(xsVar(1), xsID("length"), xsInteger(size));
						xsResult = xsCall1(xsVar(0), xsID("parse"), xsVar(1));	
						self->result = xsMarshall(xsResult);
					}
				}
			}
			xsCatch {
			}
		}
	}
	xsEndHostSandboxCode();
}
예제 #29
0
void KPR_canvasRenderingContext2D_isPointInPathStroke(xsMachine *the)
{
	FskCanvas2dContext	ctx			= xsGetHostData(xsThis);
	FskCanvas2dPath		path		= NULL;
	xsNumberValue		x, y;

	if (xsIsInstanceOf(xsArg(0), xsGet(xsGet(xsGlobal, xsID_KPR), xsID("path2D")))) {	/* ctx.isPointInPathStroke(path, x, y) */
		path = xsGetHostData(xsArg(0));
		x = xsToNumber(xsArg(1));
		y = xsToNumber(xsArg(2));
	} else {																			/* ctx.isPointInPathStroke(x, y) */
		x = xsToNumber(xsArg(0));
		y = xsToNumber(xsArg(1));
	}
	xsResult = xsBoolean(FskCanvas2dIsPointInPathStroke(ctx, path, x, y));
}
예제 #30
0
void KPR_canvasRenderingContext2D_clip(xsMachine *the)
{
	FskCanvas2dContext	ctx			= xsGetHostData(xsThis);
	FskCanvas2dPath		path		=  NULL;
	SInt32				fillRule	= kFskCanvas2dFillRuleNonZero;
	int					numArgs		= xsToInteger(xsArgc);

	if (numArgs > 0) {																		/* ctx.clip(), when numArgs==0 */
		if (xsIsInstanceOf(xsArg(0), xsGet(xsGet(xsGlobal, xsID_KPR), xsID("path2D")))) {	/* ctx.clip(path) */
			path = xsGetHostData(xsArg(0));
			if (numArgs > 1)	fillRule = GetFillRule(xsToString(xsArg(1)));				/* ctx.clip(path, fillRule) */
		} else {				fillRule = GetFillRule(xsToString(xsArg(0)));				/* ctx.clip(fillRule) */
		}
	}
	FskCanvas2dPathClip(ctx, path, fillRule);
}