예제 #1
0
파일: IoClutterColor.c 프로젝트: BMeph/io
//doc ClutterColor toHLS(h, l, s)
IO_METHOD(IoClutterColor, toHLS) {
  float h = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0)),
        l = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 1)),
        s = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 2));

  clutter_color_to_hls(&IOCCOLOR(self), &h, &l, &s);
  return self;
}
예제 #2
0
파일: IoClutterColor.c 프로젝트: BMeph/io
//doc ClutterColor fromHLS(h, l, s)
IO_METHOD(IoClutterColor, fromHLS) {
  ClutterColor color;
  float h = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0)),
        l = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 1)),
        s = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 2));

  clutter_color_from_hls(&color, h, l, s);

  return IoClutterColor_newWithColor(IOSTATE, color);
}
예제 #3
0
파일: IoClutterColor.c 프로젝트: BMeph/io
//doc ClutterColor fromPixel(pixel)
IO_METHOD(IoClutterColor, fromPixel) {
  ClutterColor color;
  guint32 pixel = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));

  clutter_color_from_pixel(&color, pixel);
  return IoClutterColor_newWithColor(IOSTATE, color);
}
예제 #4
0
파일: IoCoroutine.c 프로젝트: jdp/io
void IoCoroutine_rawRun(IoCoroutine *self)
{
	Coro *coro = DATA(self)->cid;

	if (!coro)
	{
		coro = Coro_new();
		DATA(self)->cid = coro;
	}

	{
		IoObject *stackSize = IoObject_getSlot_(self, IOSTATE->stackSizeSymbol);

		if(ISNUMBER(stackSize))
		{
			Coro_setStackSize_(coro, CNUMBER(stackSize));
		}
	}

	{
		IoCoroutine *current = IoState_currentCoroutine(IOSTATE);
		Coro *currentCoro = IoCoroutine_rawCoro(current);
		//IoState_stackRetain_(IOSTATE, self);
		Coro_startCoro_(currentCoro, coro, self, (CoroStartCallback *)IoCoroutine_coroStart);
		//IoState_setCurrentCoroutine_(IOSTATE, current);
	}
}
예제 #5
0
IO_METHOD(IoSandbox, doSandboxString)
{
	/*doc Sandbox doSandboxString(aString)
	Evaluate aString inside the Sandbox.
	*/

	IoState *boxState = IoSandbox_boxState(self);
	char *s = IoMessage_locals_cStringArgAt_(m, locals, 0);

	IoObject *result = IoState_doSandboxCString_(boxState, s);

	if (ISSYMBOL(result))
	{
		return IOSYMBOL(CSTRING(result));
	}

	if (ISSEQ(result))
	{
		return IOSEQ(IOSEQ_BYTES(result), IOSEQ_LENGTH(result));
	}

	if (ISNUMBER(result))
	{
		return IONUMBER(CNUMBER(result));
	}

	return IONIL(self);
}
예제 #6
0
파일: IoClutterColor.c 프로젝트: BMeph/io
//doc ClutterColor shade(amount)
IO_METHOD(IoClutterColor, shade) {
  ClutterColor result;
  double factor = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));
  clutter_color_shade(&IOCCOLOR(self), factor, &result);

  return IoClutterColor_newWithColor(IOSTATE, result);
}
예제 #7
0
파일: IoCFFIArray.c 프로젝트: bomma/io
IoCFFIArray *IoCFFIArray_atPut(IoCFFIArray *self, IoObject *locals, IoMessage *m)
{
	int pos;
	IoObject *value, *arrayType, *d;
	char *ptr;

	pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));
	value = IoMessage_locals_valueArgAt_(m, locals, 1);

	if ( pos >= DATA(self)->arraySize ) {
		IoState_error_(IOSTATE, m, "index out of bounds");
		return IONIL(self);
	}

	arrayType = IoObject_getSlot_(self, IOSYMBOL("arrayType"));
	ptr = ((char *)DATA(self)->buffer) + (DATA(self)->itemSize * pos);

	d = IOCLONE(arrayType);
	IoCFFIDataType_rawSetValue(d, value);
	memcpy(ptr, (void *)IoCFFIDataType_ValuePointerFromObject_(self, d), DATA(self)->itemSize);

	if ( DATA(self)->keepValuesRefs ) {
		DATA(self)->keepValuesRefs[pos] = IOREF(d);
	}

	return self;
}
예제 #8
0
파일: IoAsyncRequest.c 프로젝트: Akiyah/io
IoObject *IoAsyncRequest_write(IoAsyncRequest *self, IoObject *locals, IoMessage *m)
{
	/*doc AsyncRequest write(fileOffset, aSeq, bufferOffset, numberOfBytesToWrite)
	Submits an async write request. Returns nil on error, self otherwise. 
	*/
	
	int r;
	IoSeq *data;
	UArray *ba;
	int bufferOffset;
	int bytesToWrite;

	IOCB(self)->aio_offset = (size_t)CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));

	data = IoMessage_locals_seqArgAt_(m, locals, 1);
	ba = IoSeq_rawUArray(data);

	bufferOffset = IoMessage_locals_intArgAt_(m, locals, 2);
	bytesToWrite = IoMessage_locals_intArgAt_(m, locals, 3);

	if (bytesToWrite > UArray_size(ba) - bufferOffset)
	{
		bytesToWrite = UArray_size(ba) - bufferOffset;
	}

	IOCB(self)->aio_nbytes = bytesToWrite;
	IOCB(self)->aio_buf = realloc(IOCB_BUFFER(self), bytesToWrite);
	memcpy(IOCB_BUFFER(self), UArray_bytes(ba), bytesToWrite);

	r = aio_write(IOCB(self));

	return r == 0 ? self : IONIL(self);
}
예제 #9
0
파일: IoNumber.c 프로젝트: Akiyah/io
IO_METHOD(IoNumber, isNan)
{
	/*doc Number isNan
	Returns true if the receiver is not a number. Otherwise returns false.
	*/

	return IOBOOL(self, isnan(CNUMBER(self)));
}
예제 #10
0
파일: IoSyslog.c 프로젝트: Akiyah/io
IoObject *IoSyslog_open(IoSyslog *self, IoObject *locals, IoMessage *m)
{
	/*doc Syslog open(aPriority, someOptions, optionalIdentity)
	Opens the syslog for writing. optionalIdentity need not be entered 
	and will default to the name of the distribution of Io you are running 
	or if you have embedded Io into your application and set 
	Lobby distribution = "foo", it will be set to "foo".
	*/
	 
	int syslog_facility, syslog_options;
	//int i, max;
	char *syslog_ident;

	if (DATA(self)->syslog_opened)
	{
		IoState_error_(IOSTATE, m, "System log is already open");
		return IONIL(self);
	}

	{
		DATA(self)->facility = IOREF(IoMessage_locals_numberArgAt_(m, locals, 0));
		if (ISNIL(DATA(self)->facility))
		{
			syslog_facility = LOG_USER;
		}
		else
		{
			syslog_facility = IoObject_dataUint32(DATA(self)->facility);
		}

		DATA(self)->options = IOREF(IoMessage_locals_listArgAt_(m, locals, 1));
		syslog_options = 0;
		if (ISNIL(DATA(self)->options))
		{
			syslog_options = LOG_PID | LOG_CONS;
		}
		else
		{
			List *list = IoList_rawList(DATA(self)->options);

			LIST_FOREACH(list, i, v,
				syslog_options |= (int)CNUMBER(v);
			);
		}

		syslog_ident = (char *)IOSYMBOL_BYTES(DATA(self)->ident);
		if ((strlen(syslog_ident) == 0) || ISNIL(DATA(self)->ident))
		{
			char *s = CSTRING(IoState_doCString_(IOSTATE, "Lobby distribution"));
			strncpy(syslog_ident, s, strlen(s));
		}

		openlog(syslog_ident, syslog_options, syslog_facility);
		DATA(self)->syslog_opened = 1;
		DATA(self)->syslog_mask = setlogmask(0);
		setlogmask(DATA(self)->syslog_mask);
	}
예제 #11
0
파일: IoNumber.c 프로젝트: Akiyah/io
IO_METHOD(IoNumber, repeat)
{
	/*doc Number repeat(optionalIndex, expression)
	Evaluates message a number of times that corresponds to the receivers
	integer value. This is significantly  faster than a for() or while() loop.
	*/

	IoMessage_assertArgCount_receiver_(m, 1, self);

	{
		IoState *state = IOSTATE;
		IoSymbol *indexSlotName;
		IoMessage *doMessage;
		double i, max = CNUMBER(self);
		IoObject *result = IONIL(self);

		if(IoMessage_argCount(m) > 1)
		{
			indexSlotName = IoMessage_name(IoMessage_rawArgAt_(m, 0));
			doMessage = IoMessage_rawArgAt_(m, 1);
		}
		else
		{
			indexSlotName = 0;
			doMessage = IoMessage_rawArgAt_(m, 0);
		}

		IoState_pushRetainPool(state);

		for (i = 0; i < max; i ++)
		{
			/*
			if (result != locals && result != self)
			{
				IoState_immediatelyFreeIfUnreferenced_(state, result);
			}
			*/

			IoState_clearTopPool(state);

			if (indexSlotName)
			{
				IoObject_setSlot_to_(locals, indexSlotName, IONUMBER(i));
			}

			result = IoMessage_locals_performOn_(doMessage, locals, locals);

			if (IoState_handleStatus(IOSTATE))
			{
				break;
			}
		}

		IoState_popRetainPoolExceptFor_(IOSTATE, result);
		return result;
	}
}
예제 #12
0
파일: IoCFFIArray.c 프로젝트: akimd/io
IoCFFIArray *IoCFFIArray_at(IoCFFIArray *self, IoObject *locals, IoMessage *m)
{
	int pos;
	char *ptr;

	//TODO check limits
	pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));
	ptr = ((char *)DATA(self)->buffer) + (DATA(self)->itemSize * pos);
	return IoCFFIDataType_objectFromData_(IoObject_getSlot_(self, IOSYMBOL("arrayType")), (void *)ptr);
}
예제 #13
0
파일: IoClutter.c 프로젝트: akimd/io
IO_METHOD(IoClutter, ungrabPointer) {
    IoObject *device_n = IoMessage_locals_valueArgAt_(m, locals, 0);

    if(ISNUMBER(device_n))
        clutter_ungrab_pointer_for_device(CNUMBER(device_n));
    else
        clutter_ungrab_pointer();

    return self;
}
예제 #14
0
파일: IoClutter.c 프로젝트: akimd/io
//doc Clutter grabPointer(actor[, deviceId])
IO_METHOD(IoClutter, grabPointer) {
    ClutterActor *actor = IOCACTOR(IoMessage_locals_clutterActorArgAt_(m, locals, 0));
    IoObject *device_n = IoMessage_locals_valueArgAt_(m, locals, 1);

    if(ISNUMBER(device_n))
        clutter_grab_pointer_for_device(actor, CNUMBER(device_n));
    else
        clutter_grab_pointer(actor);

    return self;
}
예제 #15
0
파일: IoCFFIPointer.c 프로젝트: akimd/io
IoObject *IoCFFIPointer_at(IoCFFIPointer *self, IoObject *locals, IoMessage *m)
{
	int pos;
	IoObject *pointedToType;
	char *ptr;

	pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));
	pointedToType = IoObject_getSlot_(self, IOSYMBOL("pointedToType"));
	ptr = ((char *)*(DATA(self)->valuePointer)) + (IoCFFIDataType_ffiType(pointedToType)->size * pos);
	
	return IoCFFIDataType_objectFromData_(pointedToType, (void *)ptr);
}
예제 #16
0
파일: IoCFFIArray.c 프로젝트: bomma/io
IoCFFIArray *IoCFFIArray_at(IoCFFIArray *self, IoObject *locals, IoMessage *m)
{
	int pos;
	char *ptr;

	pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));

	if ( pos >= DATA(self)->arraySize ) {
		IoState_error_(IOSTATE, m, "index out of bounds");
		return IONIL(self);
	}

	ptr = ((char *)DATA(self)->buffer) + (DATA(self)->itemSize * pos);
	return IoCFFIDataType_objectFromData_(IoObject_getSlot_(self, IOSYMBOL("arrayType")), (void *)ptr);
}
예제 #17
0
파일: IoTagDB.c 프로젝트: Akiyah/io
IoObject *IoTagDB_keyAtIndex(IoTagDB *self, IoObject *locals, IoMessage *m)
{
	/*doc TagDB keyAtIndex(indexNumber)
	Returns the key at the specified index of nil if the index is out of range.
	*/
	
	TagDB *tdb = DATA(self);
	IoNumber *index = IoMessage_locals_numberArgAt_(m, locals, 0);
	Datum *key = TagDB_keyAtIndex_(tdb, CNUMBER(index));
	
	if (!key) 
	{
		return IONIL(self);
	}
	
	return IoSeq_newWithData_length_(IOSTATE, (void *)(key->data), key->size);
}
예제 #18
0
파일: IoClutterUnits.c 프로젝트: ADTSH/io
//doc ClutterUnits -(otherUnit)
IO_METHOD(IoClutterUnits, subtract) {
  IoObject *other     = IoMessage_locals_valueArgAt_(m, locals, 0);
  int self_in_pixels  = clutter_units_to_pixels(&IOCUNITS(self)),
        other_in_pixels = 0;
  ClutterUnits units;

  if(ISNUMBER(other)) {
    other_in_pixels = CNUMBER(other);
  } else if(ISCLUTTERUNITS(other)) {
    other_in_pixels = clutter_units_to_pixels(&IOCUNITS(other));
  } else {
    IoState_error_(IOSTATE, m, "ClutterUnits arithmetic works only for Numbers and other ClutterUnits.");
    return IONIL(self);
  }

  clutter_units_from_pixels(&units, self_in_pixels - other_in_pixels);
  return IoClutterUnits_newWithUnits(IOSTATE, units);
}
예제 #19
0
파일: IoCFFIArray.c 프로젝트: akimd/io
IoCFFIArray *IoCFFIArray_atPut(IoCFFIArray *self, IoObject *locals, IoMessage *m)
{
	int pos;
	IoObject *value, *d;
	char *ptr;

	//TODO check limits and types
	pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));
	value = IoMessage_locals_valueArgAt_(m, locals, 1);

	ptr = ((char *)DATA(self)->buffer) + (DATA(self)->itemSize * pos);

	d = IOCLONE(IoObject_getSlot_(self, IOSYMBOL("arrayType")));
	IoCFFIDataType_rawSetValue(d, value);
	memcpy(ptr, (void *)IoCFFIDataType_ValuePointerFromObject_(NULL, d), DATA(self)->itemSize);

	return self;
}
예제 #20
0
파일: IoCFFIPointer.c 프로젝트: akimd/io
IoObject *IoCFFIPointer_atPut(IoCFFIPointer *self, IoObject *locals, IoMessage *m)
{
	int pos;
	IoObject *value, *pointedToType, *d;
	char *ptr;

	//TODO comprobar overrun y coincidencia de tipos
	pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));
	value = IoMessage_locals_valueArgAt_(m, locals, 1);

	pointedToType = IoObject_getSlot_(self, IOSYMBOL("pointedToType"));
	ptr = ((char *)*(DATA(self)->valuePointer)) + (IoCFFIDataType_ffiType(pointedToType)->size * pos);

	d = IOCLONE(pointedToType);
	IoCFFIDataType_rawSetValue(d, value);
	memcpy(ptr, (void *)IoCFFIDataType_ValuePointerFromObject_(NULL, d), IoCFFIDataType_ffiType(pointedToType)->size);

	return self;
}
예제 #21
0
파일: IoLoudmouth.c 프로젝트: ADTSH/io
//doc Loudmouth connect Connects to the server. Returns <code>self</code>.
IoObject *IoLoudmouth_connect(IoLoudmouth *self, IoObject *locals, IoMessage *m) {
//  Q: Should we io_free() these?
  IoSeq* username   = IoObject_getSlot_(self, IOSYMBOL("username"));
  IoSeq* password   = IoObject_getSlot_(self, IOSYMBOL("password"));
  IoSeq* resource   = IoObject_getSlot_(self, IOSYMBOL("resource"));
  IoSeq* host       = IoObject_getSlot_(self, IOSYMBOL("host"));
  IoNumber* port    = IoObject_getSlot_(self, IOSYMBOL("port"));
  IoObject* use_ssl = IoObject_getSlot_(self, IOSYMBOL("useSsl"));

  IOASSERT(ISSEQ(username), "Loudmouth: username should be a Sequence");
  IOASSERT(ISSEQ(password), "Loudmouth: password should be a Sequence");
  IOASSERT(ISSEQ(resource), "Loudmouth: resource should be a Sequence");
  IOASSERT(ISSEQ(host),     "Loudmouth: host should be a Sequence");
  IOASSERT(ISNUMBER(port),  "Loudmouth: port should be a Number");

  if(LMCONN(self) == NULL) {
    LmConnection *connection = lm_connection_new_with_context(CSTRING(host), main_context);
    IoObject_setDataPointer_(self, connection);

    lm_connection_set_jid(connection, CSTRING(IoObject_getSlot_(self, IOSYMBOL("jid"))));
    lm_connection_set_port(connection, CNUMBER(port));

    if(ISTRUE(use_ssl) && lm_ssl_is_supported()) {
      LmSSL *ssl = lm_ssl_new(NULL, onSslError, NULL, NULL);
      lm_connection_set_ssl(connection, ssl);
      lm_ssl_unref(ssl);
    }

    LmMessageHandler* handler = lm_message_handler_new(onXmppMessage, self, NULL);
    lm_connection_register_message_handler(
      connection, handler,
      LM_MESSAGE_TYPE_MESSAGE, LM_HANDLER_PRIORITY_NORMAL
    );
    lm_message_handler_unref(handler);

    lm_connection_set_disconnect_function(connection, onXmppDisconnect, NULL, NULL);
  }

  lm_connection_open(LMCONN(self), onXmppConnect, self, NULL, NULL);
  return self;
}
예제 #22
0
파일: IoAsyncRequest.c 프로젝트: Akiyah/io
IoObject *IoAsyncRequest_read(IoAsyncRequest *self, IoObject *locals, IoMessage *m)
{
	/*doc AsyncRequest read(aSeq, numberOfBytes)
	Submits an async read request. Returns nil on error, self otherwise. 
	*/
	int r;

	IOCB(self)->aio_offset = (size_t)CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));
	IOCB(self)->aio_nbytes = IoMessage_locals_intArgAt_(m, locals, 1);

	if (!IOCB_BUFFER(self))
	{
		IOCB(self)->aio_buf = calloc(1, IOCB(self)->aio_nbytes);
	}
	else
	{
		IOCB(self)->aio_buf = realloc(IOCB_BUFFER(self), IOCB(self)->aio_nbytes);
	}

	r = aio_read(IOCB(self));

	return r == 0 ? self : IONIL(self);
}