Exemplo n.º 1
0
Arquivo: IoFont.c Projeto: 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) );
}
Exemplo n.º 2
0
Arquivo: IoFont.c Projeto: Teslos/io
IoObject *IoFont_drawString(IoFont *self, IoObject *locals, IoMessage *m)
{
	/*doc Font drawString(aString, optionalStartIndex, optionalEndIndex)
	Draws aString using the optional start and end indexes, if supplied. Returns self.
<p>
Note; Fonts are drawn as RGBA pixel maps. These blending options are recommended:
<pre>	
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
</pre>	
	*/

	IoSymbol *textString = IoMessage_locals_seqArgAt_(m, locals, 0);
	int startIndex = 0;
	int endIndex;

	if (IoMessage_argCount(m) > 1)
	{
		startIndex = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 1));
		if (startIndex > (int)IoSeq_rawSize(textString)) startIndex = (int)IoSeq_rawSize(textString);
	}

	if (IoMessage_argCount(m) > 2)
	{
		endIndex = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 2));
	}
	else
	{
		endIndex = IoSeq_rawSize(textString);
	}

	GLFont_drawString(DATA(self)->font, CSTRING(textString) , startIndex, endIndex);
	IoFont_checkError(self, locals, m);
	return self;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
0
Arquivo: IoCurses.c Projeto: Akiyah/io
IoObject *IoCurses_setScrollingRegion(IoCurses *self, IoObject *locals, IoMessage *m) {
    /*doc Curses setScrollingRegion(top, bottom) 
    Sets the scrolling region; top and bottom are the line numbers of the top
    and button margin. Returns self.
    */
    int top = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 0));
    int bot = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 1));
    if(setscrreg(top, bot) == ERR)
    {
        IoCurses_showError(self, m, "Curses.scroll", "Failed to set the scrolling region.");
    }
    return self;
}
Exemplo n.º 6
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);
}
Exemplo n.º 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;
}
Exemplo n.º 8
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);
}
Exemplo n.º 9
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);
}
Exemplo n.º 10
0
Arquivo: IoCurses.c Projeto: Akiyah/io
IoObject *IoCurses_move(IoCurses *self, IoObject *locals, IoMessage *m)
{
	/*doc Curses move(x, y)
	Moves the cursor to column y and row x on the terminal. 
	(0, 0) is at the top-left of the terminal. Returns self.
	*/

	int x = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 0));
	int y = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 1));

	if (move(y, x) == ERR)
	{
		IoCurses_showError(self, m, "Curses.move", "Failed to move cursor.");
	}

	return self;
}
Exemplo n.º 11
0
Arquivo: IoSyslog.c Projeto: 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);
	}
Exemplo n.º 12
0
Arquivo: IoNumber.c Projeto: Akiyah/io
IO_METHOD(IoNumber, add_)
{
	/*doc Number +(aNumber)
	Returns a new number that is the sum of the receiver and aNumber.
	*/
	
	IoNumber *other = IoMessage_locals_numberArgAt_(m, locals, 0);
	return IONUMBER(DATA(self) + DATA(other));
}
Exemplo n.º 13
0
Arquivo: IoFont.c Projeto: Teslos/io
IoObject *IoFont_stringIndexAtWidth(IoFont *self, IoObject *locals, IoMessage *m)
{
	/*doc Font stringIndexAtWidth(aString, startIndex, width)
	Returns the max index of the character in String (starting at startIndex) 
	that fits within width.
	*/

	IoSymbol *text = IoMessage_locals_seqArgAt_(m, locals, 0);
	int startIndex;
	int width;
	//IOASSERT(IoMessage_argCount(m) == 2, "requires 3 arguments");
	startIndex = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 1));
	if (startIndex > (int)IoSeq_rawSize(text)) startIndex = (int)IoSeq_rawSize(text);

	width = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 2));

	return IONUMBER(GLFont_stringIndexAtWidth(DATA(self)->font, CSTRING(text), startIndex, width));
}
Exemplo n.º 14
0
Arquivo: IoFont.c Projeto: Teslos/io
IoObject *IoFont_lengthOfCharacter(IoFont *self, IoObject *locals, IoMessage *m)
{
	/*doc Font widthOfCharacter(aNumber)
	Returns the width of the character specified by aNumber in the receiver's font.
	*/

	unsigned char c = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 0));
	return IONUMBER( GLFont_lengthOfCharacter_( DATA(self)->font, c) );
}
Exemplo n.º 15
0
Arquivo: IoNumber.c Projeto: Akiyah/io
IO_METHOD(IoNumber, subtract)
{
	/*doc Number -(aNumber)
	Returns a new number that is the difference of the receiver and aNumber.
	*/
	
	IoNumber *other = IoMessage_locals_numberArgAt_(m, locals, 0);
	return IONUMBER(DATA(self) - DATA(other));
}
Exemplo n.º 16
0
Arquivo: IoNumber.c Projeto: Akiyah/io
IO_METHOD(IoNumber, min)
{
	/*doc Number min(aNumber)
	Returns the lesser of the receiver and aNumber.
	*/

	IoNumber *other = IoMessage_locals_numberArgAt_(m, locals, 0);
	return (DATA(self) < DATA(other)) ? (IoObject *)self : (IoObject *)other;
}
Exemplo n.º 17
0
Arquivo: IoNumber.c Projeto: Akiyah/io
IO_METHOD(IoNumber, atan2)
{
	/*doc Number atan2(aNumber)
	Returns a number with the arc tangent of y/x where y is the receiver and x is aNumber.
	*/
	
	IoNumber *other = IoMessage_locals_numberArgAt_(m, locals, 0);
	return IONUMBER(atan2(DATA(self), DATA(other)));
}
Exemplo n.º 18
0
Arquivo: IoNumber.c Projeto: Akiyah/io
IO_METHOD(IoNumber, multiply)
{
	/*doc Number *(aNumber)
	Returns a new number that is the product of the receiver and aNumber.
	*/
	
	IoNumber *other = IoMessage_locals_numberArgAt_(m, locals, 0);
	return IONUMBER(DATA(self) * DATA(other));
}
Exemplo n.º 19
0
Arquivo: IoNumber.c Projeto: Akiyah/io
IO_METHOD(IoNumber, divide)
{
	/*doc Number /(aNumber)
	Returns a new number with the value of the receiver diveded by aNumber.
	*/
	
	IoNumber *other = IoMessage_locals_numberArgAt_(m, locals, 0);
	return IONUMBER(DATA(self) / DATA(other));
}
Exemplo n.º 20
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);
}
Exemplo n.º 21
0
IO_METHOD(IoMessage, argAt)
{
	/*doc Message argAt(indexNumber)
	Returns Message object for the specified argument or Nil if none exists.
	*/

	int index =  IoNumber_asInt(IoMessage_locals_numberArgAt_(m , locals, 0));
	IoObject *v = List_at_(DATA(self)->args, index);
	return v ? v : IONIL(self);
}
Exemplo n.º 22
0
Arquivo: IoCurses.c Projeto: Akiyah/io
IoObject *IoCurses_nodelay(IoCurses *self, IoObject *locals, IoMessage *m)
{
	/*doc Curses nodelay(aBoolean)
	Enables or disables block during read. 
	If aNumber is zero, nodelay is set to be false, otherwise it is set to be true.
	*/

	int b = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 0));
	nodelay(stdscr, b);
	return self;
}
Exemplo n.º 23
0
size_t IoMessage_locals_sizetArgAt_(IoMessage *self, IoObject *locals, int n)
{
	long v = IoNumber_asLong(IoMessage_locals_numberArgAt_(self, locals, n));

	if(v < 0)
	{
		IoState_error_(IOSTATE, self, "IoMessage_locals_sizetArgAt_ attempt to get size_t value from negative number %i", v);
		return 0;
	}

	return v;
}
Exemplo n.º 24
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);
}
Exemplo n.º 25
0
IoObject *IoSQLite3_setTimeoutSeconds(IoSQLite3 *self, IoObject *locals, IoMessage *m)
{
	/*doc SQLite3 setTimeoutSeconds(aNumber)
	Sets the open timeout to aNumber. If aNumber is 0, an open
	call will never timeout. Returns self. 
	*/

	IoNumber *num = IoMessage_locals_numberArgAt_(m, locals, 0);
	IOASSERT(IoNumber_asDouble(num) >= 0, "SQLite timeout must be a positive number");
	DATA(self)->timeoutSeconds = IoNumber_asDouble(num);
	return self;
}
Exemplo n.º 26
0
Arquivo: IoNumber.c Projeto: Akiyah/io
IO_METHOD(IoNumber, mod)
{
	/*doc Number %(aNumber)
	Returns the receiver modulus aNumber.
	*/

	/*doc Number mod(aNumber)
	Returns the receiver modulus aNumber.
	*/

	IoNumber *other = IoMessage_locals_numberArgAt_(m, locals, 0);
	return IONUMBER(fmod(DATA(self), DATA(other)));
}
Exemplo n.º 27
0
Arquivo: IoNumber.c Projeto: Akiyah/io
IO_METHOD(IoNumber, pow)
{
	/*doc Number pow(aNumber)
	Returns the value of the receiver to the aNumber power.
	*/
	
	/*doc Number **(aNumber)
	Same as pow(aNumber).
	*/
	
	IoNumber *other = IoMessage_locals_numberArgAt_(m, locals, 0);
	return IONUMBER(pow(DATA(self), DATA(other)));
}
Exemplo n.º 28
0
//doc ClutterActorBox with(x1, y1, x2, y2)
IO_METHOD(IoClutterActorBox, with) {
  float x1 = IoMessage_locals_floatArgAt_(m, locals, 0),
        y1 = IoMessage_locals_floatArgAt_(m, locals, 1),
        x2 = IoMessage_locals_floatArgAt_(m, locals, 2),
        y2 = IoMessage_locals_floatArgAt_(m, locals, 3);

  ClutterActorBox *actorBox = clutter_actor_box_new(x1, y1, x2, y2);
  IoClutterActorBox *klone = IoClutterActorBox_newWithActorBox(IOSTATE, actorBox);

  IoObject_setSlot_to_(klone,
    IOSYMBOL("x1"), IoMessage_locals_numberArgAt_(m, locals, 0)
  );

  IoObject_setSlot_to_(klone,
    IOSYMBOL("y1"), IoMessage_locals_numberArgAt_(m, locals, 1)
  );

  IoObject_setSlot_to_(klone,
    IOSYMBOL("x2"), IoMessage_locals_numberArgAt_(m, locals, 2)
  );

  IoObject_setSlot_to_(klone,
    IOSYMBOL("y2"), IoMessage_locals_numberArgAt_(m, locals, 3)
  );

  IoObject_setSlot_to_(klone,
    IOSYMBOL("width"), IONUMBER(clutter_actor_box_get_width(actorBox))
  );

  IoObject_setSlot_to_(klone,
    IOSYMBOL("height"), IONUMBER(clutter_actor_box_get_height(actorBox))
  );

  IoObject_setSlot_to_(klone,
    IOSYMBOL("area"), IONUMBER(clutter_actor_box_get_area(actorBox))
  );

  return klone;
}
Exemplo n.º 29
0
IoValue *IoSocket_asyncReadLine(IoSocket *self, IoValue *locals, IoMessage *m)
{
	if(self->activeReadLine)
	{
		delete self->activeReadLine;
	}

    IoNumber *size = (IoNumber*)IoMessage_locals_numberArgAt_(m, locals, 0);
	int trueSize = IoNumber_asInt(size);
	char* buffer = (char*)malloc(trueSize + 1);
	memset(buffer, 0, trueSize + 1);
	self->activeReadLine = CReadLineSocket::NewL(self->socket, self, buffer, trueSize);
	self->activeReadLine->StartReadLineL();
	return (IoValue*)self;
}
Exemplo n.º 30
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);
}