Пример #1
0
//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
//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
//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
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
//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 *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
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
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
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
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 *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
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
//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
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 *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
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
//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 *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
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
//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
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);
}