Esempio n. 1
0
File: IoDate.c Progetto: Akiyah/io
IO_METHOD(IoDate, gmtOffsetSeconds)
{
	/*doc Date gmtOffsetSeconds
	Returns the system's seconds east of UTC.
	*/

	time_t t = time(NULL);
	const struct tm *tp = localtime(&t);
#if defined(__CYGWIN__) || defined(_WIN32)
	return IONUMBER(_timezone);
#else
	return IONUMBER(tp->tm_gmtoff);
#endif
}
Esempio n. 2
0
File: IoFile.c Progetto: achoy/io
IO_METHOD(IoFile, foreach)
{
	/*doc File foreach(optionalIndex, value, message)
	For each byte, set index to the index of the byte
and value to the number containing the byte value and execute aMessage.
Example usage:
<p>
<pre>	
aFile foreach(i, v, writeln("byte at ", i, " is ", v))
aFile foreach(v, writeln("byte ", v))
</pre>	
*/
	IoObject *result;

	IoSymbol *indexSlotName, *characterSlotName;
	IoMessage *doMessage;
	int i = 0;

	IoFile_assertOpen(self, locals, m);

	result = IONIL(self);

	IoMessage_foreachArgs(m, self, &indexSlotName, &characterSlotName, &doMessage);

	for (;;)
	{
		int c = getc(DATA(self)->stream);

		if (c == EOF)
		{
			break;
		}

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

		IoObject_setSlot_to_(locals, characterSlotName, IONUMBER(c));
		result = IoMessage_locals_performOn_(doMessage, locals, locals);

		if (IoState_handleStatus(IOSTATE))
		{
			break;
		}

		i ++;
	}
	return result;
}
Esempio n. 3
0
IO_METHOD(IoClutterActor, getRotation) {
  ClutterRotateAxis axis = IoMessage_locals_intArgAt_(m, locals, 0);
  float x = 0,
        y = 0,
        z = 0;
  double angle = clutter_actor_get_rotation(IOCACTOR(self), axis, &x, &y, &z);

  IoObject *rotation = IoObject_new(IOSTATE);
  IoObject_setSlot_to_(rotation, IOSYMBOL("x"),     IONUMBER(x));
  IoObject_setSlot_to_(rotation, IOSYMBOL("y"),     IONUMBER(y));
  IoObject_setSlot_to_(rotation, IOSYMBOL("z"),     IONUMBER(z));
  IoObject_setSlot_to_(rotation, IOSYMBOL("angle"), IONUMBER(angle));

  return rotation;
}
Esempio n. 4
0
IO_METHOD(IoClutterActor, getClip) {
  float xoff    = 0,
        yoff    = 0,
        width   = 0,
        height  = 0;
  IoObject *result = IoObject_new(IOSTATE);

  clutter_actor_get_clip(IOCACTOR(self), &xoff, &yoff, &width, &height);
  IoObject_setSlot_to_(result, IOSYMBOL("xOff"),    IONUMBER(xoff));
  IoObject_setSlot_to_(result, IOSYMBOL("yOff"),    IONUMBER(yoff));
  IoObject_setSlot_to_(result, IOSYMBOL("width"),   IONUMBER(width));
  IoObject_setSlot_to_(result, IOSYMBOL("height"),  IONUMBER(height));

  return result;
}
Esempio n. 5
0
IoObject *IoTheoraInfo_frameHeight(IoTheoraInfo *self, IoObject *locals, IoMessage *m)
{
	/*doc TheoraInfo frameHeight
	The encoded frame height.
	*/
	return IONUMBER(DATA(self)->frame_height);
}
Esempio n. 6
0
File: IoDBI.c Progetto: BMeph/io
IoObject *IoDBI_initWithDriversPath(IoDBI *self, IoObject *locals,
			IoMessage *m)
{
	/*doc DBI initWithDriversPath 
	Initialize the DBI environment with the specified libdbi driver path.
	*/
	IoObject *dir = IoMessage_locals_valueArgAt_(m, locals, 0);

	if (ISSYMBOL(dir))
	{
		DATA(self)->driverCount = dbi_initialize(CSTRING(dir));
	}
	else
	{
		IoState_error_(IOSTATE, m, "argument 0 to method '%s' must be a Symbol, not a '%s'\n",
			CSTRING(IoMessage_name(m)), IoObject_name(dir));
	}

	if (DATA(self)->driverCount == -1)
	{
		IoState_error_(IOSTATE, m, "*** IoDBI error during dbi_initialize\n");
	}
	else
	{
		DATA(self)->didInit = 1;
	}

	return IONUMBER(DATA(self)->driverCount);
}
Esempio n. 7
0
IoObject *IoAppleSensors_getKeyboardBrightness(IoAppleSensors *self, IoObject *locals, IoMessage *m)
{
	/*doc AppleSensors getKeyboardBrightness
		Returns a number for the keyboard brightness.
	*/
	return IONUMBER(getKeyboardBrightness());
}
Esempio n. 8
0
void IoEvDNSRequest_callback(int result, char type, int count, int ttl, void *addresses, void *arg)
{
	IoEvDNSRequest *self = arg;
	//type is either DNS_IPv4_A or DNS_PTR or DNS_IPv6_AAAA

	IoObject_setSlot_to_(self, IOSYMBOL("ttl"), IONUMBER(ttl));

	if(result == DNS_ERR_NONE)
	{
		IoList *ioAddresses = IoList_new(IOSTATE);
		IoObject_setSlot_to_(self, IOSYMBOL("addresses"), ioAddresses);
		
		int i;
		for (i = 0; i < count; i ++)
		{
			//addresses needs to be cast according to type
			uint32_t a = ((uint32_t *)addresses)[i];
			struct in_addr addr;
			char *ip;
			addr.s_addr = htonl(get32(rr->rdata));
			ip = (char *)inet_ntoa(addr);
			IoList_rawAppend_(ioAddresses, IOSYMBOL(ip));
		}
	}
	else 
	{
		IoObject_setSlot_to_(self, IOSYMBOL("error"), IOSYMBOL("fail"));
	}

	
	IoMessage *m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("handleResponse"), IOSYMBOL("IoEvDNSRequest"));
	IoMessage_locals_performOn_(m, self, self);
}
Esempio n. 9
0
IoObject *IoImage_decodingHeightHint(IoImage *self, IoObject *locals, IoMessage *m)
{
	/*doc Image decodingHeightHint
	Returns the decoding height hint.
	*/
	return IONUMBER(Image_decodingHeightHint(DATA(self)->image));
}
Esempio n. 10
0
File: IoFont.c Progetto: Teslos/io
IoObject *IoFont_lengthOfString(IoFont *self, IoObject *locals, IoMessage *m)
{
	/*doc Font widthOfString(aString)
	Returns a Number with the width that aString would render 
	to with the receiver's current settings.
	*/

	IoSymbol *text = IoMessage_locals_seqArgAt_(m, locals, 0);
	int startIndex = 0;
	int max = IoSeq_rawSize(text);
	int endIndex = max;

	if (IoMessage_argCount(m) == 2)
	{
		startIndex = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 1));
		if (startIndex > max) startIndex = max;
	}

	if (IoMessage_argCount(m) > 2)
	{
		endIndex = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 2));
		if (startIndex > max) endIndex = max;
	}

	return IONUMBER( GLFont_lengthOfString( DATA(self)->font, CSTRING(text), startIndex, endIndex) );
}
Esempio n. 11
0
IoObject *IoAsyncRequest_descriptor(IoAsyncRequest *self, IoObject *locals, IoMessage *m)
{
	/*doc AsyncRequest descriptor
	Returns the descriptor for the request.
	*/
	return IONUMBER(IOCB(self)->aio_fildes);
}
Esempio n. 12
0
IoObject *IoAsyncRequest_position(IoAsyncRequest *self, IoObject *locals, IoMessage *m)
{
	/*doc AsyncRequest position
	Returns a Number for the position of the descriptor.
	*/
	return IONUMBER(IOCB(self)->aio_offset);
}
Esempio n. 13
0
IoObject *IoAsyncRequest_numberOfBytes(IoAsyncRequest *self, IoObject *locals, IoMessage *m)
{
	/*doc AsyncRequest numberOfBytes
	Returns the number of bytes associated with the request.
	*/
	return IONUMBER(IOCB(self)->aio_nbytes);
}
Esempio n. 14
0
IoObject *IoMemcached_deserialize(IoMemcached *self, char *cvalue, size_t size, uint32_t flags) {
	IoObject *object;

	switch(flags) {
		case _FLAG_NUMBER:
			object = IONUMBER(atof(cvalue));
			break;
		case _FLAG_NIL:
			object = IOSTATE->ioNil;
			break;
		case _FLAG_BOOLEAN:
			if(strncmp(cvalue, "1", 1) == 0)
				object = IOSTATE->ioTrue;
			else
				object = IOSTATE->ioFalse;
			break;
		case _FLAG_OBJECT:
			//object = IoState_doCString_(self, cvalue);
			IoState_pushRetainPool(IOSTATE);
			IoSeq *serialized = IoSeq_newWithCString_length_(IOSTATE, cvalue, size);
			object = IoObject_rawDoString_label_(self, serialized, IOSYMBOL("IoMemcached_deserialize"));
			IoState_popRetainPoolExceptFor_(IOSTATE, object);
			break;
		default:
			object = IoSeq_newWithCString_length_(IOSTATE, cvalue, size);
	}

	return object;
}
Esempio n. 15
0
IoObject *IoTheoraComment_count(IoTheoraComment *self, IoObject *locals, IoMessage *m)
{
	/*doc TheoraComment count
	Returns the number of comments.
	*/
	return IONUMBER(DATA(self)->comments);
}
Esempio n. 16
0
File: IoTagDB.c Progetto: Akiyah/io
IoObject *IoTagDB_size(IoTagDB *self, IoObject *locals, IoMessage *m)
{
	/*doc TagDB size
	Returns number of keys in the database.
	*/
	return IONUMBER(TagDB_size(DATA(self)));
}
Esempio n. 17
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);
}
Esempio n. 18
0
IoObject *IoRegexMatches_position(IoRegexMatches *self, IoObject *locals, IoMessage *m)
{
	/*doc RegexMatches position
	Returns the search position as an index in the string.
	*/
	return IONUMBER(DATA(self)->position);
}
Esempio n. 19
0
IO_METHOD(IoClutterActor, getPreferredHeight) {
  float for_width       = IoMessage_locals_floatArgAt_(m, locals, 0),
        min_height      = 0,
        natural_height  = 0;

  clutter_actor_get_preferred_height(
    IOCACTOR(self),
    for_width, &min_height, &natural_height
  );

  IoObject *result = IoObject_new(IOSTATE);
  IoObject_setSlot_to_(result, IOSYMBOL("minHeight"),      IONUMBER(min_height));
  IoObject_setSlot_to_(result, IOSYMBOL("naturalHeight"),  IONUMBER(natural_height));

  return result;
}
Esempio n. 20
0
IoObject *IoRegexMatches_endPosition(IoRegexMatches *self, IoObject *locals, IoMessage *m)
{
	/*doc RegexMatches endPosition
	Returns the index in the string where the receiver stops searching.
	*/
	return IONUMBER(DATA(self)->endPosition);
}
Esempio n. 21
0
IoObject *IoCollector_maxAllocatedBytes(IoCollector *self, IoObject *locals, IoMessage *m)
{
	/*doc Collector maxAllocatedBytes
	Returns the maximum number of bytes allocated by the collector.
	*/
	return IONUMBER(io_maxAllocatedBytes());
}
Esempio n. 22
0
IoObject *IoAppleSensors_getDisplayBrightness(IoAppleSensors *self, IoObject *locals, IoMessage *m)
{
	/*doc AppleSensors getDisplayBrightness
		Returns a number for the display brightness.
	*/
	return IONUMBER(getDisplayBrightness());
}
Esempio n. 23
0
IO_METHOD(IoObject, activeCpus)
{
	/*doc System activeCpus
	Returns the number of active CPUs.
	*/

	int cpus = 1;
#if defined(CTL_HW)
	int mib[2];
	size_t len = sizeof(cpus);
	mib[0] = CTL_HW;
#if defined(HW_AVAILCPU)
	mib[1] = HW_AVAILCPU;
#elif defined(HW_NCPU)
	mib[1] = HW_NCPU;
#else
#error
#endif
	sysctl(mib, 2, &cpus, &len, NULL, 0);
#elif defined(_SC_NPROCESSORS_ONLN)
	cpus = sysconf(_SC_NPROCESSORS_ONLN);
#elif defined(_SC_NPROC_ONLN)
	cpus = sysconf(_SC_NPROC_ONLN);
#elif defined(WIN32)
	SYSTEM_INFO si;
	GetSystemInfo(&si);
	cpus = si.dwNumberOfProcessors;
#else
#error
#endif
	return IONUMBER(cpus);
}
Esempio n. 24
0
File: IoRegex.c Progetto: ADTSH/io
IoObject *IoRegex_namedCaptures(IoRegex *self, IoObject *locals, IoMessage *m)
{
	/*doc Regex namedCaptures
	Returns a Map that contains the index of each named group.
	*/
	
	IoMap *map = DATA(self)->namedCaptures;
	NamedCapture *namedCaptures = 0, *capture = 0;

	if (map)
		return map;

	map = DATA(self)->namedCaptures = IOREF(IoMap_new(IOSTATE));

	capture = namedCaptures = Regex_namedCaptures(IoRegex_rawRegex(self));
	
	if (!namedCaptures)
		return map;

	while (capture->name) 
	{
		IoMap_rawAtPut(map, IOSYMBOL(capture->name), IONUMBER(capture->index));
		capture++;
	}
	
	free(namedCaptures);
	return map;
}
Esempio n. 25
0
IoDynLib *IoDynLib_callPluginInitFunc(IoDynLib *self, IoObject *locals, IoMessage *m)
{
	/*doc DynLib callPluginInit(functionName)
	Call's the dll function of the specified name. 
	Returns the result as a Number or raises an exception on error.
	*/
	
	intptr_t rc = 0;
	intptr_t *params = NULL;
	void *f = DynLib_pointerForSymbolName_(DATA(self),
									CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0)));
	if (f == NULL)
	{
		IoState_error_(IOSTATE, m, "Error resolving call '%s'.",
					CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0)));
		return IONIL(self);
	}

	if (IoMessage_argCount(m) < 1)
	{
		IoState_error_(IOSTATE, m, "Error, you must give an init function name to check for.");
		return IONIL(self);
	}

	params = io_calloc(1, sizeof(intptr_t) * 2);

	params[0] = (intptr_t)IOSTATE;
	params[1] = (intptr_t)IOSTATE->lobby;
	rc = ((intptr_t (*)(intptr_t, intptr_t))f)(params[0], params[1]);
	io_free(params);

	return IONUMBER(rc);
}
Esempio n. 26
0
IoObject *IoTheoraInfo_frameWidth(IoTheoraInfo *self, IoObject *locals, IoMessage *m)
{
	/*doc TheoraInfo frameWidth
	The encoded frame width.
	*/
	return IONUMBER(DATA(self)->frame_width);
}
Esempio n. 27
0
IO_METHOD(IoSeq, asBinaryNumber)
{
	/*doc Sequence asBinaryNumber
	Returns a Number containing the first 8 bytes of the
	receiver without casting them to a double. Endian is same as machine.
	*/

	IoNumber *byteCount = IoMessage_locals_valueArgAt_(m, locals, 0);
	size_t max = UArray_size(DATA(self));
	int bc = sizeof(double);
	double d = 0;

	if (!ISNIL(byteCount))
	{
		bc = IoNumber_asInt(byteCount);
	}

	if (max < bc)
	{
		IoState_error_(IOSTATE, m, "requested first %i bytes, but Sequence only contians %i bytes", bc, max);
	}

	memcpy(&d, UArray_bytes(DATA(self)), bc);
	return IONUMBER(d);
}
Esempio n. 28
0
IO_METHOD(IoSeq, itemSize)
{
	/*doc Sequence itemSize
	Returns number of bytes in each element. 
	*/

	return IONUMBER(UArray_itemSize(DATA(self)));
}
Esempio n. 29
0
IO_METHOD(IoSeq, sizeInBytes)
{
	/*doc Sequence sizeInBytes
	Returns the length in bytes of the receiver.
	*/

	return IONUMBER(UArray_sizeInBytes(DATA(self)));
}
Esempio n. 30
0
IoValue *IoSocket_open(IoSocket *self, IoValue *locals, IoMessage *m)
{ 
	self->socket->ResetBuffer();
	IoState* state = (IoState*)self->tag->state;
	CConsoleControl* control = (CConsoleControl*)IoState_userData(state);
	
	return (IoValue *)IONUMBER(self->socket->socket.Open(control->socketServer, KAfInet, KSockStream, KProtocolInetTcp));
}