示例#1
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);
}
示例#2
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);
}
示例#3
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();
}
示例#4
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);
}
示例#5
0
void
xs_console_load(xsMachine *the)
{
	xsVars(1);
	xsSetInteger(xsVar(0), CONSOLE_LOG_FILE);
	xsSet(xsThis, xsID("LOGFILE"), xsVar(0));
	xsSetInteger(xsVar(0), CONSOLE_XSBUG);
	xsSet(xsThis, xsID("XSBUG"), xsVar(0));
}
示例#6
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);
}
示例#7
0
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;
}
示例#8
0
文件: i2c.c 项目: dadongdong/kinomajs
void xs_i2c_readBlock(xsMachine *the)
{
	FskErr err;
	xsI2C i2c = xsGetHostData(xsThis);
	int argc = xsToInteger(xsArgc), i;
	int format = 2;
    SInt32 dataSize = xsToInteger(xsArg(0)), readCount;
	UInt8 data[32];

	xsThrowIfNULL(i2c);

    DBG_I2C("xs_i2c_readBlock\n");

	if ((dataSize > 32) || (dataSize <= 0))
		xsThrowDiagnosticIfFskErr(kFskErrInvalidParameter, "I2C readBlock invalid size %d. %s", (int)dataSize, i2c->diagnosticID);

	FskPinI2CSetAddress(i2c->pin, i2c->address);
	err = FskPinI2CReadBytes(i2c->pin, dataSize, &readCount, data);
    if (err) {
        xsTraceDiagnostic("I2C readBlock failed with error %s %s.", FskInstrumentationGetErrorString(err), i2c->diagnosticID);
        goto bail;
    }

    if (argc > 1) {
        int t = xsTypeOf(xsArg(1));
        if ((xsNumberType == t) || (t == xsIntegerType))
            format = xsToInteger(xsArg(1));
        else {
            char *formatString = xsToString(xsArg(1));
            if (0 == FskStrCompare(formatString, "Buffer"))
                format = 2;
            else if (0 == FskStrCompare(formatString, "Chunk"))
                format = 0;
            else if (0 == FskStrCompare(formatString, "Array"))
                format = 1;
        }
    }
    
    if (2 == format) {
        xsResult = xsArrayBuffer(data, readCount);
    }
    else if (0 == format) {
        xsResult = xsNew1(xsGlobal, xsID("Chunk"), xsInteger(readCount));
        FskMemMove(xsGetHostData(xsResult), data, readCount);
    }
    else if (1 == format) {
        xsResult = xsNew1(xsGlobal, xsID("Array"), xsInteger(readCount));
        for (i = 0; i < readCount; i++)
            xsSet(xsResult, i, xsInteger(data[i]));
    }
    
bail:
    if (err)
		xsError(err);
}
示例#9
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);
}
示例#10
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);
	}
}
示例#11
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
}
示例#12
0
void KPR_host_get_profiling(xsMachine* the)
{
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	Boolean result = false;
	xsBeginHost(application->the);
	{
		result = xsTest(xsCall0(xsGet(xsGlobal, xsID("xs")), xsID("isProfiling")));
	}
	xsEndHost(application->the);
	xsResult = xsBoolean(result);
}
示例#13
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));
	}
}
示例#14
0
void KPR_system_alert(xsMachine* the)
{
	int argc = xsToInteger(xsArgc);
	MSGBOXPARAMSW params;
	xsStringValue string;
	xsIntegerValue result;
	xsVars(1);
	params.cbSize = sizeof(params);
	params.hwndOwner = NULL;
	params.hInstance = FskMainGetHInstance();
	params.lpszText = NULL;
	params.lpszCaption = xsStringToWideString("Kinoma Code");
	params.dwStyle = MB_ICONSTOP;
	params.dwContextHelpId = 0;
	params.lpfnMsgBoxCallback = NULL;
	params.dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
	if ((argc > 0) && xsTest(xsArg(0))) {
		if (xsFindString(xsArg(0), xsID_type, &string)) {
			if (!FskStrCompare(string, "about"))
				params.dwStyle = MB_ICONINFORMATION;
			else if (!FskStrCompare(string, "stop"))
				params.dwStyle = MB_ICONSTOP;
			else if (!FskStrCompare(string, "note"))
				params.dwStyle = MB_ICONEXCLAMATION;
		}
		if (xsFindResult(xsArg(0), xsID_prompt)) {
			xsVar(0) = xsResult;
		}
		if (xsFindResult(xsArg(0), xsID_info)) {
			xsVar(0) = xsCall1(xsVar(0), xsID("concat"), xsString("\n\n"));
			xsVar(0) = xsCall1(xsVar(0), xsID("concat"), xsResult);
		}
		params.lpszText = xsStringToWideString(xsToString(xsVar(0)));
		if (xsFindResult(xsArg(0), xsID_buttons)) {
			if (xsIsInstanceOf(xsResult, xsArrayPrototype)) {
				xsIntegerValue c = xsToInteger(xsGet(xsResult, xsID_length));
				if (c == 3)
					params.dwStyle |= MB_YESNOCANCEL;
				else if (c == 2)
					params.dwStyle |= MB_OKCANCEL;
				else
					params.dwStyle |= MB_OK;
			}
		}
	}
	result = MessageBoxIndirectW(&params);
	if (params.lpszText)
		CoTaskMemFree((LPVOID *)params.lpszText);
	if (params.lpszCaption)
		CoTaskMemFree((LPVOID *)params.lpszCaption);
	if ((argc > 1) && xsTest(xsArg(1)))
		(void)xsCallFunction1(xsArg(1), xsNull, ((result == IDYES) || (result == IDOK)) ? xsTrue : (result == IDNO) ? xsFalse : xsUndefined);
}
示例#15
0
void
xs_z_div2(xsMachine *the)
{
	z_t *z = xsGetHostData(xsThis);

	xsVars(2);
	z_call3(the, z, kcl_z_div, &xsVar(1));
	xsVar(0) = xsResult;
	xsResult = xsNewInstanceOf(xsObjectPrototype);
	xsSet(xsResult, xsID("q"), xsVar(0));
	xsSet(xsResult, xsID("r"), xsVar(1));
}
示例#16
0
void
xs_system_get_timezone(xsMachine *the)
{
	struct timezone tz;

	xsVars(1);
	mc_gettimeofday(NULL, &tz);
	xsResult = xsNewInstanceOf(xsObjectPrototype);
	xsSetInteger(xsVar(0), tz.tz_minuteswest);
	xsSet(xsResult, xsID("timedifference"), xsVar(0));
	xsSetInteger(xsVar(0), tz.tz_dsttime);
	xsSet(xsResult, xsID("dst"), xsVar(0));
}
示例#17
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
}
示例#18
0
文件: mc_usb.c 项目: cugfeng/kinomajs
static void
usb_callback(xsMachine *the, void *closure)
{
	char *buf = closure;

	xsBeginHost(the);
	xsVars(2);
	xsGet(xsVar(0), xsGlobal, xsID("require"));
	xsSetString(xsVar(1), "CLI");
	xsCall(xsResult, xsVar(0), xsID("weak"), &xsVar(1), NULL);
	xsSetString(xsVar(1), buf);
	xsCall_noResult(xsResult, xsID("evaluate"), &xsVar(1), NULL);
	xsEndHost(the);
}
示例#19
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);
}
示例#20
0
void KPR_canvasLinearGradient_setStyle(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsArg(0));
	xsNumberValue x0 = xsToNumber(xsGet(xsThis, xsID("x0")));
	xsNumberValue y0 = xsToNumber(xsGet(xsThis, xsID("y0")));
	xsNumberValue x1 = xsToNumber(xsGet(xsThis, xsID("x1")));
	xsNumberValue y1 = xsToNumber(xsGet(xsThis, xsID("y1")));
	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)))
		FskCanvas2dSetStrokeStyleLinearGradient(ctx, x0, y0, x1, y1, c, stops);
	else
		FskCanvas2dSetFillStyleLinearGradient(ctx, x0, y0, x1, y1, c, stops);
}
示例#21
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
}
示例#22
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
}
示例#23
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;
				}
			}
		}
示例#24
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
}
示例#25
0
int main(int argc, char* argv[]) 
{
	xsAllocation anAllocation = {
		2048 * 1024, /* initialChunkSize */
		512 * 1024, /* incrementalChunkSize */
		1000 * 1000, /* initialHeapCount */	
		50 * 1000, /* incrementalHeapCount */
		1024, /* stackCount */
		8192, /* symbolCount */
		1993 /* symbolModulo */
	};
	xsMachine* aMachine;
	int argi;
	int result = 1;

	for (argi = 0; argi < argc; argi++){
		result = strncmp(argv[argi], "--help", strlen("--help"));
		if(!result) {
			printHelp();
			exit(0);
		}
	}
	
	result = 1;

	gxProperties = calloc(mxPropertyModulo, sizeof(xsSlot));
	if (gxProperties) {
		aMachine = xsNewMachine(&anAllocation, &kprconfigGrammar, NULL);
		if (aMachine) {
			xsBeginHost(aMachine);
			{
				xsTry {
					xsResult = xsNewInstanceOf(xsArrayPrototype);
					for (argi = 0; argi < argc; argi++)
						xsSet(xsResult, argi, xsString(argv[argi]));
					(void)xsCall1(xsGlobal, xsID("main"), xsResult);
					result = 0;
				}
				xsCatch {
					char* aMessage = xsToString(xsGet(xsException, xsID("message")));
					fprintf(stderr, "### %s\n", aMessage);
				}
			}
			xsEndHost(aMachine);
			xsDeleteMachine(aMachine);
		}
		else
			fprintf(stderr, "### Cannot allocate machine!\n");
	}
示例#26
0
void KPR_Message_patch(xsMachine* the)
{
	xsResult = xsGet(xsGlobal, xsID("Message"));
	xsNewHostProperty(xsResult, xsID("BUFFER"), xsString("BUFFER"), xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsNewHostProperty(xsResult, xsID("CHUNK"), xsString("CHUNK"), xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsNewHostProperty(xsResult, xsID("DOM"), xsString("DOM"), xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsNewHostProperty(xsResult, xsID("JSON"), xsString("JSON"), xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsNewHostProperty(xsResult, xsID("TEXT"), xsString("TEXT"), xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet);
	xsNewHostProperty(xsResult, xsID("URI"), xsNewHostFunction(KPR_Message_URI, 1), xsDefault, xsDontScript);
	xsNewHostProperty(xsResult, xsID("cancelReferrer"), xsNewHostFunction(KPR_Message_cancelReferrer, 1), xsDefault, xsDontScript);
	xsNewHostProperty(xsResult, xsID("notify"), xsNewHostFunction(KPR_Message_notify, 1), xsDefault, xsDontScript);
}
示例#27
0
文件: kprPins.c 项目: basuke/kinomajs
void KprPinsInvoke(KprService service, KprMessage message)
{
	FskErr err = kFskErrNone;
	KprPins self = gPins;
	if (KprMessageContinue(message)) {
		KprPinsListener listener = NULL;
		KprPinsListenerFind(&listener, self, message);
		if (listener) listener->useCount++;
		if (!FskStrCompareWithLength(message->parts.path, "close", message->parts.pathLength)) {
			if (listener) {
				xsBeginHostSandboxCode(listener->the, NULL);
				{
                    {
						xsTry {
							(void)xsCall0(xsAccess(listener->pins), xsID("close"));
						}
						xsCatch {
							err = exceptionToFskErr(the);
						}
					}

                    while (listener->pollers)
                        KprPinsPollerDispose(listener->pollers);
				}
				xsEndHostSandboxCode();
				KprPinsListenerDispose(listener, self);
				listener = NULL;
			}
			else {
				err = kFskErrNotFound;
			}
		}
		else if (!FskStrCompareWithLength(message->parts.path, "configure", message->parts.pathLength)) {
示例#28
0
void KprDebugMachineLoadView(KprDebugMachine self, int theView, char* thePath, int theLine)
{
	FskErr err = kFskErrNone;
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;
//	FskFileInfo info;
//	FskFileMapping map = NULL;
//	FskDebugStr("%s: %d - %s:%d", __FUNCTION__, theView, thePath, theLine);
	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	xsVar(0) = xsAccess(debug->behavior);
	
	if (xsFindResult(xsVar(0), xsID("onMachineFileChanged"))) {
		(void)xsCallFunction5(xsResult, xsVar(0), xsString(self->address), xsInteger(theView), xsNull, thePath ? xsString(thePath) : xsNull, xsInteger(theLine));
	}
//	if (kFskErrNone == FskFileGetFileInfo(thePath, &info) && (kFskDirectoryItemIsFile == info.filetype)) {
//		unsigned char *data;
//		FskInt64 size;
//		BAIL_IF_ERR(err = FskFileMap(thePath, &data, &size, 0, &map));
//		xsVar(0) = xsAccess(debug->behavior);
//		
//		if (xsFindResult(xsVar(0), xsID("onMachineFileChanged"))) {
//			(void)xsCallFunction5(xsResult, xsVar(0), xsString(self->address), xsInteger(theView), xsNull, xsString(thePath), xsInteger(theLine));
//		}
//	}
bail:
//	FskFileDisposeMap(map);
	xsThrowIfFskErr(err);
}
示例#29
0
void
xs_system_set_timezone(xsMachine *the)
{
	struct timezone tz;

	xsVars(1);
	xsGet(xsVar(0), xsArg(0), xsID("timedifference"));
	tz.tz_minuteswest = xsToInteger(xsVar(0));
	xsGet(xsVar(0), xsArg(0), xsID("dst"));
	tz.tz_dsttime = xsToInteger(xsVar(0));
	mc_settimeofday(NULL, &tz);
	if (xsHas(xsArg(0), xsID("timezone"))) {
		xsGet(xsVar(0), xsArg(0), xsID("timezone"));
		mc_env_set_default("TIME_ZONE", xsToString(xsVar(0)));
	}
}
示例#30
0
// dashes
void KPR_canvasRenderingContext2D_setLineDash(xsMachine *the)
{
	FskCanvas2dContext	ctx		= xsGetHostData(xsThis);
	UInt32				len		= xsToInteger(xsGet(xsArg(0), xsID("length")));	/* Array of even length */
	double				dash[kCanvas2DMaxDashCycles*2];
	UInt32				i;

	if (len) {
		if (len > sizeof(dash) / sizeof(dash[0])) {								/* If too large, truncate */
			kprTraceDiagnostic(the, "dash length %u > %u is too long", (unsigned)len, sizeof(dash) / sizeof(dash[0]));
			len = sizeof(dash) / sizeof(dash[0]);
		}
		i = (len & 1) ? (len * 2) : len;										/* If odd, double the length to make it even */
		for (i = 0; i < len; ++i)
			dash[i] = xsToNumber(xsGetAt(xsArg(0), xsInteger(i)));				/* Copy from xs Array to C array to interface to FskCanvas2dSetLineDash() */
		if (len & 1) {															/* If odd, ... */
			for (i = 0; i < len; ++i)
				dash[i + len] = dash[i];										/* ... replicate. Now it is even. */
		}
		else {
			len /= 2;															/* Len here is the number of cycles */
		}
	}
	(void)FskCanvas2dSetLineDash(ctx, len, dash);								/* Set the context line dash state */
	return;
}