예제 #1
0
파일: IoFont.c 프로젝트: 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;
}
예제 #2
0
파일: IoFont.c 프로젝트: 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) );
}
예제 #3
0
IO_METHOD(IoObject, shellExecute)
{
	LPCTSTR operation;
	LPCTSTR file;
	LPCTSTR parameters;
	LPCTSTR directory;
	int displayFlag;
	int result;

	operation = CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0));
	file = CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 1));
	parameters = IoMessage_argCount(m) > 2 ? CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 2)) : NULL;
	directory = IoMessage_argCount(m) > 3 ? CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 3)) : NULL;
	displayFlag = IoMessage_argCount(m) > 4 ? IoMessage_locals_intArgAt_(m, locals, 4) : SW_SHOWNORMAL;

	result = (int)ShellExecute(NULL, operation, file, parameters, directory, displayFlag);

	if(result > 32)
	{
		return self;
	}
	else
	{
		return (IoObject *)IoError_newWithMessageFormat_(IOSTATE, "ShellExecute Error %i", result);
	}
}
예제 #4
0
파일: IoRandom.c 프로젝트: Akiyah/io
IoObject *IoRandom_value(IoObject *self, IoObject *locals, IoMessage *m)
{
	/*doc Random value(optionalArg1, optionalArg2)
	If called with:
	<ul>
	<li> no arguments, it returns a floating point
	random Number between 0 and 1.
	<li> one argument, it returns a floating point random
	Number between 0 and optionalArg1.
	<li> two arguments, it returns a floating point random
	Number between optionalArg1 and optionalArg2.
	</ul>
	*/

	double f = RandomGen_randomDouble(DATA(self));
	double result = 0;

	if (IoMessage_argCount(m) > 0)
	{
		double a = IoMessage_locals_doubleArgAt_(m, locals, 0);

		if (IoMessage_argCount(m) > 1)
		{
			double b = IoMessage_locals_doubleArgAt_(m, locals, 1);

			if (a == b )
			{
				result = a;
			}
			else
			{
				result = a + (b - a) * f;
			}
		}
		else
		{
			if (a == 0)
			{
				result = 0;
			}
			else
			{
				result = a * f;
			}
		}
	}
	else
	{
		result = f;
	}

	return IONUMBER(result);
}
예제 #5
0
파일: IoDuration.c 프로젝트: ADTSH/io
IO_METHOD(IoDuration, asString)
{
/*doc Duration asString(formatString)
Returns a string representation of the receiver. The formatString argument is optional. If present, the returned string will be formatted according to ANSI C date formating rules.
<p>
<pre>	
%y years without century as two-digit decimal number (00-99)
%Y year with century as four-digit decimal number

%d days
%H hour as two-digit 24-hour clock decimal integer (00-23)
%M minute as a two-digit decimal integer (00-59)
%S second as a two-digit decimal integer (00-59)

The default format is "%Y %d %H:%M:%S".
</pre>
*/
	UArray *ba;
	char *format = NULL;

	if (IoMessage_argCount(m) == 1)
	{
		format = CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0));
	}

	ba = Duration_asUArrayWithFormat_(DATA(self), format);
	return IoState_symbolWithUArray_copy_convertToFixedWidth(IOSTATE, ba, 0);
}
예제 #6
0
파일: IoMemcached.c 프로젝트: ADTSH/io
/*doc Memcached replace(key, value[, expiration])
Asks memcached to store the value identified by the key,
but only if the server *does* already hold data for this key.
Returns true on success, false if there is already data for this key.
Otherwise raises an exception.
*/
IoObject *IoMemcached_replace(IoMemcached *self, IoObject *locals, IoMessage *m)
{
	IoSeq    *key   = IoMessage_locals_seqArgAt_(m, locals, 0);
	IoObject *value = IoMessage_locals_quickValueArgAt_(m, locals, 1);

	time_t expiration = IoMessage_argCount(m) == 3 ? IoMessage_locals_intArgAt_(m, locals, 2) : 0;

	uint32_t flags;
	size_t size;
	char *cvalue = IoMemcached_serialize(self, locals, value, &size, &flags);

	memcached_return_t rc;
	rc = memcached_replace(DATA(self)->mc,
		CSTRING(key), IOSEQ_LENGTH(key),
		cvalue, size,
		expiration, flags
	);

	free(cvalue);

	if(rc != MEMCACHED_SUCCESS && rc != MEMCACHED_NOTSTORED)
		IoState_error_(IOSTATE, m, memcached_strerror(DATA(self)->mc, rc));

	// MEMCACHED_NOTSTORED is a legitmate error in the case of a collision.
	if(rc == MEMCACHED_NOTSTORED)
		return IOSTATE->ioFalse;

	return IOSTATE->ioTrue; // MEMCACHED_SUCCESS
}
예제 #7
0
파일: IoDirectory.c 프로젝트: Akiyah/io
IO_METHOD(IoDirectory, exists)
{
	/*doc Directory exists(optionalPath)
	Returns true if the Directory path exists, and false otherwise.
	If optionalPath string is provided, it tests the existance of that path instead. 
	*/

	IoSymbol *path = DATA(self)->path;
	DIR *dirp;

	if (IoMessage_argCount(m) > 0)
	{
		path = IoMessage_locals_symbolArgAt_(m, locals, 0);
	}

	dirp = opendir(CSTRING(path));

	if (!dirp)
	{
		return IOFALSE(self);
	}

	(void)closedir(dirp);
	return IOTRUE(self);
}
예제 #8
0
파일: IoCFunction.c 프로젝트: doublec/io
IO_METHOD(IoCFunction, performOn)
{
	/*doc CFunction performOn(target, blockLocals, optionalMessage, optionalContext)
	Activates the CFunctions with the supplied settings.
	*/

	IoObject *bTarget = IoMessage_locals_valueArgAt_(m, locals, 0);
	IoObject *bLocals = locals;
	IoObject *bMessage = m;
	IoObject *bContext = bTarget;
	int argCount = IoMessage_argCount(m);

	if (argCount > 1)
	{
		bLocals = IoMessage_locals_valueArgAt_(m, locals, 1);
	}

	if (argCount > 2)
	{
		bMessage = IoMessage_locals_valueArgAt_(m, locals, 2);
	}

	if (argCount > 3)
	{
		bContext = IoMessage_locals_valueArgAt_(m, locals, 3);
	}

	return IoCFunction_activate(self, bTarget, bLocals, bMessage, bContext);
}
예제 #9
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);
}
예제 #10
0
파일: IoVector_gl.c 프로젝트: ADTSH/io
IoObject *IoSeq_drawQuad(IoSeq *self, IoObject *locals, IoMessage *m)
{
	IoSeq_assertIsVector(self, locals, m);
	{
	vec2f p = IoSeq_vec2f(self);
	double x, y, w, h;
	double s = 0;

	if (IoMessage_argCount(m) > 1)
	{
		s = -IoMessage_locals_doubleArgAt_(m, locals, 1);
	}

	x = s;
	y = s;
	w = (p.x) - (s*2);
	h = (p.y) - (s*2);

	glBegin(GL_QUADS);
	glVertex2d(w, h);
	glVertex2d(x, h);
	glVertex2d(x, y);
	glVertex2d(w, y);
	glEnd();
	}
	return self;
}
예제 #11
0
IO_METHOD(IoSeq, inclusiveSlice)
{
	/*doc Sequence inclusiveSlice(inclusiveStartIndex, inclusiveEndIndex)
	Returns a new string containing the subset of the
	receiver from the inclusiveStartIndex to the inclusiveEndIndex. The inclusiveEndIndex argument
	is optional. If not given, it is assumed to be the end of the string. 
	*/

	long fromIndex = IoMessage_locals_longArgAt_(m, locals, 0);
	long last = UArray_size(DATA(self));
	UArray *ba;

	if (IoMessage_argCount(m) > 1)
	{
		last = IoMessage_locals_longArgAt_(m, locals, 1);
	}

	if (last == -1)
	{
		last = UArray_size(DATA(self));
	}
	else
	{
		last = last + 1;
	}
	
	ba = UArray_slice(DATA(self), fromIndex, last);

	if (ISSYMBOL(self))
	{
		return IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);
	}

	return IoSeq_newWithUArray_copy_(IOSTATE, ba, 0);
}
예제 #12
0
IO_METHOD(IoDirectory, exists)
{
    /*doc Directory exists(optionalPath)
    Returns true if the Directory path exists, and false otherwise.
    If optionalPath string is provided, it tests the existence of that path instead.
    */

    IoSymbol *path = DATA(self)->path;
    DIR *dirp;

    if (IoMessage_argCount(m) > 0)
    {
        path = IoMessage_locals_symbolArgAt_(m, locals, 0);
    }

#if !defined(_WIN32) || defined(__CYGWIN__)
    dirp = opendir(CSTRING(path));

    if (!dirp)
    {
        return IOFALSE(self);
    }

    (void)closedir(dirp);
    return IOTRUE(self);
#else
    {
        DWORD d = GetFileAttributes(CSTRING(path));
        return (d != INVALID_FILE_ATTRIBUTES) && (d & FILE_ATTRIBUTE_DIRECTORY) ? IOTRUE(self) : IOFALSE(self);
    }
#endif
}
예제 #13
0
IO_METHOD(IoSeq, replaceFirstSeq)
{
	/*doc Sequence replaceFirstSeq(aSequence, anotherSequence, optionalStartIndex)
	Returns a new Sequence with the first occurance of aSequence
	replaced with anotherSequence in the receiver. If optionalStartIndex is
	provided, the search for aSequence begins at that index. Returns self.
	*/

	IoSeq *subSeq   = IoMessage_locals_seqArgAt_(m, locals, 0);
	IoSeq *otherSeq = IoMessage_locals_seqArgAt_(m, locals, 1);
	size_t startIndex = 0;

	if (IoMessage_argCount(m) > 2)
	{
		startIndex = IoMessage_locals_longArgAt_(m, locals, 2);
	}

	IO_ASSERT_NOT_SYMBOL(self);

	{
		UArray *a = DATA(self);
		UArray *b = DATA(subSeq);
		UArray *c = DATA(otherSeq);
		long i = UArray_find_from_(a, b, startIndex);
		if(i != -1)
		{
			UArray_removeRange(a, i, UArray_size(b));
			UArray_at_putAll_(a, i, c);
		}
	}
	return self;
}
예제 #14
0
파일: IoFile.c 프로젝트: achoy/io
IO_METHOD(IoFile, write)
{
	/*doc File write(aSequence1, aSequence2, ...)
	Writes the arguments to the receiver file. Returns self.
	*/

	int i;

	IoFile_assertOpen(self, locals, m);
	IoFile_assertWrite(self, locals, m);

	for (i = 0; i < IoMessage_argCount(m); i ++)
	{
		IoSymbol *string = IoMessage_locals_seqArgAt_(m, locals, i);
		UArray_writeToCStream_(IoSeq_rawUArray(string), DATA(self)->stream);

		if (ferror(DATA(self)->stream) != 0)
		{
			IoState_error_(IOSTATE, m, "error writing to file '%s'",
							UTF8CSTRING(DATA(self)->path));
		}
	}

	return self;
}
예제 #15
0
파일: IoVector_gl.c 프로젝트: ADTSH/io
IoObject *IoSeq_drawLineLoopi(IoSeq *self, IoObject *locals, IoMessage *m)
{
	IoSeq_assertIsVector(self, locals, m);
	{
	vec2f p  = IoSeq_vec2f(self);
	GLint x = (p.x);
	GLint y = (p.y);
	GLint s = 0;

	if (IoMessage_argCount(m))
	{
		s = (GLint)IoMessage_locals_doubleArgAt_(m, locals, 0);
	}

	glBegin(GL_LINES);
	glVertex2i(x-s, y-s);
	glVertex2i(s, y-s);

	glVertex2i(s, y-s);
	glVertex2i(s, s);

	glVertex2i(s, s);
	glVertex2i(x-s, s);

	glVertex2i(x-s, s);
	glVertex2i(x-s, y-s);
	glEnd();
	}
	return self;
}
예제 #16
0
파일: IoVector_gl.c 프로젝트: ADTSH/io
IoObject *IoSeq_drawQuadTo(IoSeq *self, IoObject *locals, IoMessage *m)
{
	IoSeq_assertIsVector(self, locals, m);
	{
	IoSeq *other = IoMessage_locals_pointArgAt_(m, locals, 0);
	vec2f p  = IoSeq_vec2f(self);
	vec2f p2 = IoSeq_vec2f(other);
	double x1, y1, x2, y2;
	double s = 0;

	if (IoMessage_argCount(m) > 1)
	{
		s = IoMessage_locals_doubleArgAt_(m, locals, 1);
	}

	x1 = (p.x) + s;
	y1 = (p.y) + s;
	x2 = (p2.x) - s;
	y2 = (p2.y) - s;

	glBegin(GL_QUADS);
	glVertex2d(x1, y1);
	glVertex2d(x2, y1);
	glVertex2d(x2, y2);
	glVertex2d(x1, y2);
	glEnd();
	}
	return self;
}
예제 #17
0
파일: IoNumber.c 프로젝트: Akiyah/io
IO_METHOD(IoNumber, asString)
{
/*doc Number asString(optionalIntegerDigits, optionalFactionDigits)
Returns a string representation of the receiver. For example:
<pre>
1234.5678 asString(0, 2)
</pre>	
would return:
<pre>
1234.57
</pre>	
*/
	
	if (IoMessage_argCount(m) >= 1)
	{
		int whole = IoMessage_locals_intArgAt_(m, locals, 0);
		int part = 6;
		char *s;
		size_t length;
		IoObject *n;


		if (IoMessage_argCount(m) >= 2)
		{
			part = abs(IoMessage_locals_intArgAt_(m, locals, 1));
		}

		part  = abs(part);
		whole = abs(whole);

		// If whole == 0, printf might need an arbitary size string. Instead of
		// second guessing the size, pick a really big size: 1024.
		length = 1024;
		s = io_calloc(1, length);

		snprintf(s, length, "%*.*f", whole, part, DATA(self));

		n = IOSEQ((unsigned char *)s, (size_t)strlen(s));

		io_free(s);

		return n;
	}

	return IoNumber_justAsString(self, locals, m);
}
예제 #18
0
IO_METHOD(IoSeq, appendSeq)
{
	/*doc Sequence appendSeq(object1, object2, ...)
	Calls asString on the arguments and appends the string to the receiver. Returns self. 
	*/

	int i;

	IO_ASSERT_NOT_SYMBOL(self);
	IOASSERT(IoMessage_argCount(m), "requires at least one argument");

	for (i = 0; i < IoMessage_argCount(m); i ++)
	{
		UArray_append_(DATA(self), DATA(IoMessage_locals_valueAsStringArgAt_(m, locals, i)));
	}
	return self;
}
예제 #19
0
IO_METHOD(IoSeq, append)
{
	/*doc Sequence append(aNumber)
	Appends aNumber (cast to a byte) to the receiver. Returns self. 
	*/

	int i;

	IO_ASSERT_NOT_SYMBOL(self);
	IOASSERT(IoMessage_argCount(m), "requires at least one argument");

	for (i = 0; i < IoMessage_argCount(m); i ++)
	{
		UArray_appendDouble_(DATA(self), IoMessage_locals_doubleArgAt_(m, locals, i));
	}

	return self;
}
예제 #20
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;
	}
}
예제 #21
0
파일: IoMP3Encoder.c 프로젝트: Akiyah/io
IoObject *IoMP3Encoder_encode(IoMP3Encoder *self, IoObject *locals, IoMessage *m)
{
    UArray *inBa = IoBuffer_rawUArray(IoMessage_locals_bufferArgAt_(m, locals, 0));
    /*UArray *outBa = IoBuffer_rawUArray(DATA(self)->outBuffer);*/
    
    int start = 0;
    int end = UArray_length(inBa);
    
    if (IoMessage_argCount(m) > 1) start = IoMessage_locals_intArgAt_(m, locals, 1);
    if (IoMessage_argCount(m) > 2) end = IoMessage_locals_intArgAt_(m, locals, 2);
    if (start > end)
    { IoState_error_description_(IOSTATE, m, "MP3Encoder", "range error: start > end"); }
    if (end > UArray_length(inBa))
    { IoState_error_description_(IOSTATE, m, "MP3Encoder", "range error: end > length of input buffer"); }
    
    MP3Encoder_encode(DATA(self)->encoder, UArray_bytes(inBa) + start, end);
    
    return IoMP3Encoder_checkError(self, locals, m);
}
예제 #22
0
파일: IoMySQL.c 프로젝트: jamesrburgess/io
IoObject* IoMySQL_connect(IoObject* self, IoObject* locals, IoMessage* m) {
    IoObject *host = NULL, *user = NULL, *password = NULL, *database = NULL, *port = NULL, *socket = NULL, *ssl = NULL;

    /*doc MySQL connect(host, user, password, database, port, unixSocket, useSSL)
    Connect to a MySQL database.
    */

    switch(IoMessage_argCount(m)) {
    case 7:
        ssl = IoMessage_locals_quickValueArgAt_(m, locals, 6);
    case 6:
        socket = IoMessage_locals_quickValueArgAt_(m, locals, 5);
    case 5:
        port = IoMessage_locals_quickValueArgAt_(m, locals, 4);
    case 4:
        database = IoMessage_locals_quickValueArgAt_(m, locals, 3);
    case 3:
        password = IoMessage_locals_quickValueArgAt_(m, locals, 2);
    case 2:
        user = IoMessage_locals_quickValueArgAt_(m, locals, 1);
    case 1:
        host = IoMessage_locals_quickValueArgAt_(m, locals, 0);
    }

    if(DATA(self)->connected)
    {
        mysql_close(&DATA(self)->connection);
        DATA(self)->connected = 0;
    }

    if(mysql_real_connect(
                &DATA(self)->connection,
                host && ISSEQ(host) ? IoSeq_asCString(host) : NULL,
                user && ISSEQ(user) ? IoSeq_asCString(user) : NULL,
                password && ISSEQ(password) ? IoSeq_asCString(password) : NULL,
                database && ISSEQ(database) ? IoSeq_asCString(database) : NULL,
                port && ISNUMBER(port) ? (unsigned) IoNumber_asInt(port) : 0,
                socket && ISSEQ(socket) ? IoSeq_asCString(socket) : NULL,
                ssl && ISFALSE(ssl) ? 0 : CLIENT_SSL
            )) {
        DATA(self)->connected = 1;

        IoObject_setSlot_to_(self, IOSYMBOL("host"), host ? host : IONIL(self));
        IoObject_setSlot_to_(self, IOSYMBOL("user"), user ? user : IONIL(self));
        IoObject_setSlot_to_(self, IOSYMBOL("password"), password ? password : IONIL(self));
        IoObject_setSlot_to_(self, IOSYMBOL("database"), database ? database : IONIL(self));
        IoObject_setSlot_to_(self, IOSYMBOL("port"), port ? port : IONIL(self));
        IoObject_setSlot_to_(self, IOSYMBOL("socket"), socket ? socket : IONIL(self));
        IoObject_setSlot_to_(self, IOSYMBOL("usingSSL"), ssl ? IOBOOL(self, ISTRUE(ssl)) : IOFALSE(self));
    }
    else
        IoState_error_(IOSTATE, m, "connection error(%d): %s", mysql_errno(&DATA(self)->connection), mysql_error(&DATA(self)->connection));

    return self;
}
예제 #23
0
void Level_finish(Level *self)
{
	if (self->message)
	{
		IoMessage_rawSetNext_(self->message, NULL);

		// Remove extra () we added in for operators, but do not need any more
		if ( IoMessage_argCount(self->message) == 1 )
		{
			IoMessage *arg = IoMessage_rawArgAt_(self->message, 0);

			if ( IoSeq_rawSize(IoMessage_name(arg)) == 0 && IoMessage_argCount(arg) == 1 && IoMessage_rawNext(arg) == NULL )
			{
				List_copy_(IoMessage_rawArgList(self->message), IoMessage_rawArgList(arg));
				List_removeAll(IoMessage_rawArgList(arg));
			}
		}
	}

	self->type = UNUSED;
}
예제 #24
0
파일: IoDate.c 프로젝트: bomma/io
IO_METHOD(IoDate, asString)
{
	/*doc Date asString(optionalFormatString)
	Returns a string representation of the receiver using the
receivers format. If the optionalFormatString argument is present, the
receiver's format is set to it first. Formatting is according to ANSI C
date formatting rules.
<p>
<pre>	
%a abbreviated weekday name (Sun, Mon, etc.)
%A full weekday name (Sunday, Monday, etc.)
%b abbreviated month name (Jan, Feb, etc.)
%B full month name (January, February, etc.)
%c full date and time string
%d day of the month as two-digit decimal integer (01-31)
%H hour as two-digit 24-hour clock decimal integer (00-23)
%I hour as two-digit 12-hour clock decimal integer (01-12)
%m month as a two-digit decimal integer (01-12)
%M minute as a two-digit decimal integer (00-59)
%p either "AM" or "PM"
%S second as a two-digit decimal integer (00-59)
%U number of week in the year as two-digit decimal integer (00-52)
with Sunday considered as first day of the week
%w weekday as one-digit decimal integer (0-6) with Sunday as 0
%W number of week in the year as two-digit decimal integer (00-52)
with Monday considered as first day of the week
%x full date string (no time); in the C locale, this is equivalent
to "%m/%d/%y".
%y year without century as two-digit decimal number (00-99)
%Y year with century as four-digit decimal number
%Z time zone name (e.g. EST);
null string if no time zone can be obtained
%% stands for '%' character in output string.
</pre>	
*/

	char *format = "%Y-%m-%d %H:%M:%S %Z";

	if (IoMessage_argCount(m) == 1)
	{
		format = CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0));
	}
	else
	{
		IoObject *f = IoObject_getSlot_(self, IOSYMBOL("format"));
		if (ISSEQ(f)) { format = CSTRING(f); }
	}

	{
		UArray *ba = Date_asString(DATA(self), format);
		return IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);
	}
}
예제 #25
0
파일: IoRandom.c 프로젝트: Akiyah/io
IoObject *IoRandom_gaussian(IoObject *self, IoObject *locals, IoMessage *m)
{
	/*doc Random gaussian(optionalMean, optionalStandardDeviation)
	Returns a pseudo random number between 0 and 1 with a gaussian distribution.
	*/

	double mean = 0;
	double standardDeviation = 1;

	if (IoMessage_argCount(m) > 0)
	{
		mean = IoMessage_locals_doubleArgAt_(m, locals, 0);
	}

	if (IoMessage_argCount(m) > 1)
	{
		standardDeviation = IoMessage_locals_doubleArgAt_(m, locals, 1);
	}

	return IONUMBER(RandomGen_gaussian(DATA(self), mean, standardDeviation));
}
예제 #26
0
파일: IoFont.c 프로젝트: Teslos/io
IoObject *IoFont_open(IoFont *self, IoObject *locals, IoMessage *m)
{
	/*doc Font open(optionalPath)
	Opens the font. Sets path using optionalPath if supplied. Returns self.
	*/

	if (IoMessage_argCount(m) > 0)
	{
		DATA(self)->path = IOREF(IoMessage_locals_seqArgAt_(m, locals, 0));
	}

	GLFont_loadFont( DATA(self)->font, CSTRING(DATA(self)->path) );
	IoFont_checkError(self, locals, m);
	return self;
}
예제 #27
0
파일: IoCompiler.c 프로젝트: doublec/io
IO_METHOD(IoObject, messageForString)
{
	/*doc Compiler messageForString(aString, optionalLabelString)
	Returns the compiled message object for aString.
	*/

	IoSymbol *string = IoMessage_locals_seqArgAt_(m, locals, 0);
	IoSymbol *label  = IoMessage_rawLabel(m);

	if (IoMessage_argCount(m) > 1)
	{
		label = IoMessage_locals_symbolArgAt_(m, locals, 1);
	}

	return IoMessage_newFromText_labelSymbol_(IOSTATE, CSTRING((IoSymbol *)string), (IoSymbol *)label);
}
예제 #28
0
파일: IoNumber.c 프로젝트: Akiyah/io
IO_METHOD(IoNumber, log)
{
	/*doc Number log
	Returns the logarithm of the receiver.  The base
	is taken as the value of the first argument or the constant e if
	the first argument is omitted.
	*/

	float base;
	if(IoMessage_argCount(m) > 0){
		base = DATA(IoMessage_locals_numberArgAt_(m, locals, 0));
	}
	else{
		base = (float)M_E;
	}
	return IONUMBER(log(DATA(self)) / log(base));
}
예제 #29
0
파일: IoImage.c 프로젝트: Alessandroo/io
IoObject *IoImage_save(IoImage *self, IoObject *locals, IoMessage *m)
{
	/*doc Image save(optionalPathString)
	Sets the path to optionalPathString if provided and saves the image 
	in the format specified by the path extension. Returns self on success, nil on failure.
	*/

	if (IoMessage_argCount(m) > 0)
	{
		IoSymbol *path = IoMessage_locals_symbolArgAt_(m, locals, 0);
		Image_path_(DATA(self)->image, CSTRING(path));
	}

	Image_save(DATA(self)->image);
	IoImage_checkError(self, locals, m);
	return self;
}
예제 #30
0
IO_METHOD(IoObject, exit)
{
	/*doc System exit(optionalReturnCodeNumber)
	Shutdown the IoState (io_free all objects) and return
control to the calling program (if any).
*/

	int returnCode = 0;

	if (IoMessage_argCount(m))
	{
		returnCode = IoMessage_locals_intArgAt_(m, locals, 0);
	}

	IoState_exit(IOSTATE, returnCode);
	return self;
}