コード例 #1
0
ファイル: IoUser.c プロジェクト: Akiyah/io
IoObject *IoUser_protoName(IoUser *self, IoObject *locals, IoMessage *m)
{
	/*doc User name
	Returns the current user's name.
	*/

	char *userName = (char *)getlogin();

	if (userName == NULL)
	{
		userName = getenv("LOGNAME");
	}

	if (userName == NULL)
	{
		return IONIL(self);
	}

	return IOSYMBOL(userName);
}
コード例 #2
0
ファイル: IoCompiler.c プロジェクト: doublec/io
IO_METHOD(IoObject, tokensForString)
{
	/*doc Compiler tokensForString(aString)
	Returns a list of token objects lexed from the input string.
*/

	IoSymbol *text = IoMessage_locals_seqArgAt_(m, locals, 0);
	IoList *tokensList = IoList_new(IOSTATE);
	IoLexer *lexer = IoLexer_new();
	IoSymbol *name = IOSYMBOL("name");
	IoSymbol *line = IOSYMBOL("line");
	IoSymbol *character = IOSYMBOL("character");
	IoSymbol *type = IOSYMBOL("type");

	IoLexer_string_(lexer, CSTRING(text));
	IoLexer_lex(lexer);

	if (IoLexer_errorToken(lexer))
	{
		IoSymbol *errorString  = IOSYMBOL(IoLexer_errorDescription(lexer));
		IoLexer_free(lexer);
		IoState_error_(IOSTATE, NULL, "compile error: %s", CSTRING(errorString));
	}
	else
	{
		IoToken *t;

		while ((t = IoLexer_pop(lexer)))
		{
			IoObject *tokenObject = IoObject_new(IOSTATE);

			IoObject_setSlot_to_(tokenObject, name, IOSYMBOL(IoToken_name(t)));
			IoObject_setSlot_to_(tokenObject, line, IONUMBER(IoToken_lineNumber(t)));
			IoObject_setSlot_to_(tokenObject, character, IONUMBER(IoToken_charNumber(t)));
			IoObject_setSlot_to_(tokenObject, type, IOSYMBOL(IoToken_typeName(t)));

			IoList_rawAppend_(tokensList, tokenObject);
		}
	}

	IoLexer_free(lexer);

	return tokensList;
}
コード例 #3
0
ファイル: IoAVCodec.c プロジェクト: BMeph/io
IoObject *IoAVCodec_encodeCodecNames(IoAVCodec *self, IoObject *locals, IoMessage *m)
{
	/*doc AVCodec encodeCodecNames
	Returns a list of strings with the names of the encode codecs.
	*/

	AVCodec *p = av_codec_next(NULL);
	IoList *names = IoList_new(IOSTATE);

	while (p)
	{
		if (p->encode)
		{
			IoList_rawAppend_(names, IOSYMBOL(p->name));
		}

        p = av_codec_next(p);
	}

	return names;
}
コード例 #4
0
ファイル: IoMySQL.c プロジェクト: cdcarter/io
IoObject* IoMySQL_close(IoObject* self, IoObject* locals, IoMessage* m) {
	/*#io
	docSlot("close",
		   "Closes a previously opened connection.")
	*/

	if(DATA(self)->connected)
		mysql_close(&DATA(self)->connection);

	IoObject_removeSlot_(self, IOSYMBOL("host"));
	IoObject_removeSlot_(self, IOSYMBOL("user"));
	IoObject_removeSlot_(self, IOSYMBOL("password"));
	IoObject_removeSlot_(self, IOSYMBOL("database"));
	IoObject_removeSlot_(self, IOSYMBOL("port"));
	IoObject_removeSlot_(self, IOSYMBOL("socket"));
	IoObject_removeSlot_(self, IOSYMBOL("usingSSL"));

	return self;
}
コード例 #5
0
ファイル: IoAVCodec.c プロジェクト: josip/io
IoObject *IoAVCodec_decodeCodecNames(IoAVCodec *self, IoObject *locals, IoMessage *m)
{
	/*doc AVCodec decodeCodecNames
	Returns a list of strings with the names of the decode codecs.
	*/

	AVCodec *p = first_avcodec;
	IoList *names = IoList_new(IOSTATE);

	while (p)
	{
		if (p->decode)
		{
			IoList_rawAppend_(names, IOSYMBOL(p->name));
		}

		p = p->next;
	}

	return names;
}
コード例 #6
0
ファイル: IoLoudmouth.c プロジェクト: ADTSH/io
/***  Loudmouth callbacks ***/
void onXmppConnect(LmConnection *connection, int success, void* data) {
  IoObject *self = data;
  IoMessage *m;
  if(success == 1) {
    m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("handleConnect"), IOSYMBOL("Loudmouth"));
    IoMessage_locals_performOn_(m, self, self);

    lm_connection_authenticate(
      connection,
      CSTRING(IoObject_getSlot_(self, IOSYMBOL("username"))),
      CSTRING(IoObject_getSlot_(self, IOSYMBOL("password"))),
      CSTRING(IoObject_getSlot_(self, IOSYMBOL("resource"))),
      onXmppAuth, data, NULL, NULL
    );
  } else {
    m = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("handleConnectFailure"), IOSYMBOL("Loudmouth"));
    IoMessage_locals_performOn_(m, self, self);
  }
}
コード例 #7
0
ファイル: IoTokyoCabinetPrefixCursor.c プロジェクト: ADTSH/io
IoObject *IoTokyoCabinetPrefixCursor_last(IoObject *self, IoObject *locals, IoMessage *m)
{
	/*doc TokyoCabinetPrefixCursor last
	Move cursor to last record. Returns self
	*/

	IoSeq *prefix = IoObject_getSlot_(self, IOSYMBOL("prefix"));
	IOASSERT(ISSEQ(prefix), "prefix must be a sequence");
	IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor");
	
	{
		UArray *p = UArray_clone(IoSeq_rawUArray(prefix));
		UArray_appendCString_(p, " "); // space preceeds .
		
		tcbdbcurjump(TokyoCabinetPrefixCursor(self), (const void *)UArray_bytes(p), (int)UArray_size(p));
		
		UArray_free(p);
	}
	
	return IOBOOL(self, IoTokyoCabinetPrefixCursor_keyBeginsWithPrefix_(self, prefix));
}
コード例 #8
0
ファイル: IoEditLine.c プロジェクト: cdcarter/io
IoEditLine *IoEditLine_proto(void *state)
{
	IoMethodTable methodTable[] = {
		{"hasEditLib", IoEditLine_hasEditLib},
		{"readLine", IoEditLine_readLine},
		{"addHistory", IoEditLine_addHistory},
		{NULL, NULL},
	};

	IoObject *self = IoObject_new(state);
	IoObject_tag_(self, IoEditLine_newTag(state));

	/* Make sure editline returns characters in the multi-byte charset
	   of the locale */
	setlocale(LC_CTYPE, "");

	IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoEditLineData)));
	DATA(self)->prompt  = IOSYMBOL("");
	DATA(self)->editline = el_init("io", stdin, stdout, stderr);
	DATA(self)->history = history_init();

	el_set(DATA(self)->editline, EL_CLIENTDATA, self);
	el_set(DATA(self)->editline, EL_HIST, history, DATA(self)->history);
	el_set(DATA(self)->editline, EL_PROMPT, promptCallback);
	el_set(DATA(self)->editline, EL_SIGNAL, 1);
	el_set(DATA(self)->editline, EL_EDITOR, "emacs");

	{
		HistEvent ev;
		history(DATA(self)->history, &ev, H_SETSIZE, 300);
	}

	el_source(DATA(self)->editline, NULL);

	IoState_registerProtoWithFunc_((IoState *)state, self, IoEditLine_proto);

	IoObject_addMethodTable_(self, methodTable);

	return self;
}
コード例 #9
0
ファイル: IoMemcached.c プロジェクト: ADTSH/io
// Serialize/Deserialize
char *IoMemcached_serialize(IoMemcached *self, IoObject *locals, IoObject *object, size_t *size, uint32_t *flags) {
	char *cvalue;

	if(ISSEQ(object)) {
		*flags = _FLAG_SEQUENCE;
		*size = IOSEQ_LENGTH(object);
		cvalue = (char *) malloc(*size);
		strncpy(cvalue, CSTRING(object), *size);
	}
	else if(ISNUMBER(object)) {
		*flags = _FLAG_NUMBER;
		double cnumber = IoNumber_asDouble(object);
		cvalue = (char *) malloc(128 * sizeof(char));
		*size = snprintf(cvalue, 127, "%.16f", cnumber);
	}
	else if(ISNIL(object)) {
		*flags = _FLAG_NIL;
		*size = 3;
		cvalue = (char *) malloc(3 * sizeof(char));
		strncpy(cvalue, "nil", 3);
	}
	else if(ISBOOL(object)) {
		*flags = _FLAG_BOOLEAN;
		*size = 1;
		cvalue = (char *) malloc(sizeof(char));
		if(object == IOSTATE->ioTrue)  strncpy(cvalue, "1", 1);
		if(object == IOSTATE->ioFalse) strncpy(cvalue, "0", 1);
	}
	else {
		*flags = _FLAG_OBJECT;
		IoMessage *serialize = IoMessage_newWithName_(IOSTATE, IOSYMBOL("serialized"));
		IoSeq *serialized = IoMessage_locals_performOn_(serialize, locals, object);
		*size = IOSEQ_LENGTH(serialized);
		cvalue = (char *) malloc(*size);
		strncpy(cvalue, CSTRING(serialized), *size);
	}

	return cvalue;
}
コード例 #10
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;
}
コード例 #11
0
ファイル: IoSQLite3.c プロジェクト: JoeyButler/io
IoSQLite3 *IoSQLite3_proto(void *state)
{
	IoObject *self = IoObject_new(state);
	IoObject_tag_(self, IoSQLite3_newTag(state));

	IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoSQLite3Data)));
	DATA(self)->path = IOSYMBOL(".");

	IoState_registerProtoWithId_(state, self, protoId);

	{
		IoMethodTable methodTable[] = {
		{"setPath", IoSQLite3_setPath},
		{"path", IoSQLite3_path},
		{"open", IoSQLite3_open},
		{"close", IoSQLite3_close},
		{"exec", IoSQLite3_exec},
		{"error", IoSQLite3_errorMessage},
		{"version", IoSQLite3_version},
		{"setTimeoutSeconds", IoSQLite3_setTimeoutSeconds},
		{"timeoutSeconds", IoSQLite3_timeoutSeconds},
		{"rowsChangedCount", IoSQLite3_changes},
		{"lastInsertRowId", IoSQLite3_lastInsertRowId},
		{"tableNames", IoSQLite3_tableNames},
		{"viewNames", IoSQLite3_viewNames},

		{"columnNamesOfTable", IoSQLite3_columnNamesOfTable},
		{"debugOn", IoSQLite3_debugOn},
		{"debugOff", IoSQLite3_debugOff},
		{"isOpen", IoSQLite3_isOpen},
		{"escapeString", IoSQLite3_escapeString},
		{NULL, NULL},
		};
		IoObject_addMethodTable_(self, methodTable);
	}
	return self;
}
コード例 #12
0
ファイル: IoClutterActorBox.c プロジェクト: ADTSH/io
//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;
}
コード例 #13
0
ファイル: IoRegexMatch.c プロジェクト: ADTSH/io
IoRegexMatch *IoRegexMatch_proto(void *state)
{
	IoObject *self = IoObject_new(state);
	IoObject_tag_(self, IoRegexMatch_newTag(state));

	IoObject_setDataPointer_(self, calloc(1, sizeof(IoRegexMatchData)));
	DATA(self)->regex = IONIL(self);
	DATA(self)->subject = IOSYMBOL("");
	DATA(self)->ranges = IoList_new(state);
	IoState_registerProtoWithId_(state, self, protoId);

	{
		IoMethodTable methodTable[] = {
			{"regex", IoRegexMatch_regex},
			{"subject", IoRegexMatch_subject},
			{"ranges", IoRegexMatch_ranges},
			{0, 0},
		};

		IoObject_addMethodTable_(self, methodTable);
	}

	return self;
}
コード例 #14
0
ファイル: IoCFFIPointer.c プロジェクト: akimd/io
IoCFFIPointer *IoCFFIPointer_ToType_(IoObject *type)
{
	IoObject *pointer, *self;
	IoMap *pointers;
	IoSymbol *key;

	// this is a hack so macros relying on self will work
	self = type;

	pointers = IoObject_getSlot_(IoState_protoWithInitFunction_(IOSTATE, IoCFFIPointer_proto), IOSYMBOL("pointers"));
	key = IoState_on_doCString_withLabel_(IOSTATE, type, "uniqueHexId", "IoCFFIPointer_ToType_");

	pointer = IoMap_rawAt(pointers, key);
	if (!pointer)
	{
		// create new pointer and add to cache
		pointer = IoCFFIPointer_new(IOSTATE);
		IoObject_setSlot_to_(pointer, IOSYMBOL("pointedToType"), type);

		IoMap_rawAtPut(pointers, key, pointer);
	}

	return pointer;
}
コード例 #15
0
ファイル: IoTokyoCabinetPrefixCursor.c プロジェクト: ADTSH/io
IoObject *IoTokyoCabinetPrefixCursor_jump(IoObject *self, IoObject *locals, IoMessage *m)
{
	/*doc TokyoCabinetPrefixCursor jump(key)
	Move cursor to record before key. Returns self
	*/
	
	IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0);
	int result;
	UArray *p;
	
	IoSeq *prefix = IoObject_getSlot_(self, IOSYMBOL("prefix"));
	IOASSERT(ISSEQ(prefix), "prefix must be a sequence");

	p = UArray_clone(IoSeq_rawUArray(prefix));
	UArray_appendPath_(p, IoSeq_rawUArray(key));
	
	result = tcbdbcurjump(TokyoCabinetPrefixCursor(self), 
						  (const void *)UArray_bytes(p), 
						  (int)UArray_sizeInBytes(p));
	UArray_free(p);
	
	IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor");
	return IOBOOL(self, result);
}
コード例 #16
0
ファイル: IoODEJointGroup.c プロジェクト: Akiyah/io
IoODEJointGroup *IoODEJointGroup_rawClone(IoODEJointGroup *proto)
{
	IoObject *self = IoObject_rawClonePrimitive(proto);
	IoObject_setDataPointer_(self, calloc(1, sizeof(IoODEJointGroupData)));

	if(DATA(proto)->world)
	{
		IoODEWorld *world = DATA(proto)->world;
		WORLD = world;
		IoODEWorld_addJointGroup(world, self);
		JOINTGROUPID = dJointGroupCreate(0);
		DATA(self)->joints = List_new();

		IoObject_inlineSetSlot_to_(self, IOSYMBOL("Ball"), IoODEBall_newProto(IOSTATE, self));
		IoObject_inlineSetSlot_to_(self, IOSYMBOL("Hinge"), IoODEHinge_newProto(IOSTATE, self));
		IoObject_inlineSetSlot_to_(self, IOSYMBOL("Slider"), IoODESlider_newProto(IOSTATE, self));
		IoObject_inlineSetSlot_to_(self, IOSYMBOL("Hinge2"), IoODEHinge2_newProto(IOSTATE, self));
		IoObject_inlineSetSlot_to_(self, IOSYMBOL("Universal"), IoODEUniversal_newProto(IOSTATE, self));
		IoObject_inlineSetSlot_to_(self, IOSYMBOL("Fixed"), IoODEFixed_newProto(IOSTATE, self));
		//IoObject_inlineSetSlot_to_(self, IOSYMBOL("AMotor"), IoODEAMotor_newProto(IOSTATE, self));
		//IoObject_inlineSetSlot_to_(self, IOSYMBOL("LMotor"), IoODELMotor_newProto(IOSTATE, self));
	}
	return self;
}
コード例 #17
0
ファイル: IoCFFIPointer.c プロジェクト: akimd/io
IoObject *IoCFFIPointer_value(IoCFFIPointer *self, IoObject *locals, IoMessage *m)
{
	IoObject *pointedToType;
	IoCFFIPointer *pointer;
	char *typeString, *cp, c;

	if (*(DATA(self)->valuePointer) == NULL)
	{
		//IoState_error_(IOSTATE, m, "attempt to dereference NULL pointer");
		return IONIL(self);
	}

    typeString = CSTRING(IoState_on_doCString_withLabel_(IOSTATE, self, "typeString", "IoCFFIPointer_value"));

    pointedToType = IoObject_getSlot_(self, IOSYMBOL("pointedToType"));

	if (ISCFFIPointer(pointedToType))
	{
		// we are a pointer to a pointer, so return a new Pointer
		// that points to the address of our ptr dereferenced

		cp = strrchr(typeString, '^');
		switch (c = *(++cp))
		{

#define IoCFFIPointer_value_SET_DATA_PTR(cType) \
	pointer = IOCLONE(IoCFFIPointer_ToType_(IoObject_getSlot_(pointedToType, IOSYMBOL("pointedToType")))); \
	*(DATA(pointer)->valuePointer) = *((cType **)(*(DATA(self)->valuePointer))); break
	//DATA(pointer)->ptr = *((cType **)(DATA(self)->ptr)); break

			case 'c':
			case 'b':
				IoCFFIPointer_value_SET_DATA_PTR(char);
			case 'C':
			case 'B':
				IoCFFIPointer_value_SET_DATA_PTR(unsigned char);
			case 's':
				IoCFFIPointer_value_SET_DATA_PTR(short);
			case 'S':
				IoCFFIPointer_value_SET_DATA_PTR(unsigned short);
			case 'i':
				IoCFFIPointer_value_SET_DATA_PTR(int);
			case 'I':
				IoCFFIPointer_value_SET_DATA_PTR(unsigned int);
			case 'l':
				IoCFFIPointer_value_SET_DATA_PTR(long);
			case 'L':
				IoCFFIPointer_value_SET_DATA_PTR(unsigned long);
			case 'f':
				IoCFFIPointer_value_SET_DATA_PTR(float);
			case 'd':
				IoCFFIPointer_value_SET_DATA_PTR(double);
			case '*':
				IoCFFIPointer_value_SET_DATA_PTR(char *);
			case '{':
			case '(':
			case '&':
			case '[':
			case 'v':
				IoCFFIPointer_value_SET_DATA_PTR(void);

#undef IoCFFIPointer_value_SET_DATA_PTR

			//case 'v':
			//	IoState_error_(IOSTATE, m, "attempt to dereference a void pointer");
			//	return IONIL(self);

			default:
				IoState_error_(IOSTATE, m, "unknown character '%c' in Pointer typeString", c);
				return IONIL(self);
			}
			return pointer;
	}
	else if(ISCFFIDataType(pointedToType) || ISCFFIStructure(pointedToType) || ISCFFIFunction(pointedToType) || ISCFFIArray(pointedToType))
	{
		return IoCFFIDataType_objectFromData_(pointedToType, *(DATA(self)->valuePointer));
	}
    else
	{
		IoState_error_(IOSTATE, m, "attempt to dereference Pointer object whose pointedToType is unknown.");
		return IONIL(self);
	}
}
コード例 #18
0
ファイル: IoCoroutine.c プロジェクト: jdp/io
IoObject *IoCoroutine_rawException(IoCoroutine *self)
{
	return IoObject_getSlot_(self, IOSYMBOL("exception"));
}
コード例 #19
0
ファイル: IoCoroutine.c プロジェクト: jdp/io
void IoCoroutine_rawSetException_(IoCoroutine *self, IoObject *v)
{
	IoObject_setSlot_to_(self, IOSYMBOL("exception"), v);
}
コード例 #20
0
ファイル: IoCoroutine.c プロジェクト: jdp/io
void IoCoroutine_rawRemoveException(IoCoroutine *self)
{
	IoObject_removeSlot_(self, IOSYMBOL("exception"));
}
コード例 #21
0
ファイル: IoCoroutine.c プロジェクト: jdp/io
IoObject *IoCoroutine_rawResult(IoCoroutine *self)
{
	return IoObject_getSlot_(self, IOSYMBOL("result"));
}
コード例 #22
0
ファイル: IoCoroutine.c プロジェクト: jdp/io
void IoCoroutine_rawSetResult_(IoCoroutine *self, IoObject *v)
{
	IoObject_setSlot_to_(self, IOSYMBOL("result"), v);
}
コード例 #23
0
ファイル: IoCoroutine.c プロジェクト: jdp/io
IoObject *IoCoroutine_rawParentCoroutine(IoCoroutine *self)
{
	return IoObject_getSlot_(self, IOSYMBOL("parentCoroutine"));
}
コード例 #24
0
ファイル: IoCoroutine.c プロジェクト: jdp/io
void IoCoroutine_rawSetParentCoroutine_(IoCoroutine *self, IoObject *v)
{
	IoObject_setSlot_to_(self, IOSYMBOL("parentCoroutine"), v);
}
コード例 #25
0
ファイル: IoCoroutine.c プロジェクト: jdp/io
IoObject *IoCoroutine_rawRunLocals(IoCoroutine *self)
{
	return IoObject_rawGetSlot_(self, IOSYMBOL("runLocals"));
}
コード例 #26
0
ファイル: IoMySQL.c プロジェクト: jamesrburgess/io
IoObject* IoMySQL_query(IoObject* self, IoObject* locals, IoMessage* m)
{
    /*doc MySQL query(aQueryString)
    Perform a SQL query and return a list of results.
    <pre>
    db query("SELECT * FROM accounts") foreach(println)
    </pre>
    */

    IoObject * queryString = 0x0;
    bool useMap;

    MYSQL* conn = &DATA(self)->connection;
    MYSQL_RES* result;
    MYSQL_ROW row;
    MYSQL_FIELD* column;
    char** columnNames;
    unsigned c, colLength;
    unsigned long* colLengths;
    IoObject *list, *rowObject; //, *tmpObject;

    if(IoMessage_argCount(m) < 1 || !ISSEQ(queryString = IoMessage_locals_quickValueArgAt_(m, locals, 0)))
        IoState_error_(IOSTATE, m, "argument 0 to method 'query' must be a Sequence");

    useMap = IoMessage_argCount(m) > 1 && ISTRUE(IoMessage_locals_quickValueArgAt_(m, locals, 1));

    if(!DATA(self)->connected) //printf("not connected?\n");
        IoState_error_(IOSTATE, m, "not connected yet");

    if(mysql_real_query(conn, CSTRING(queryString), IOSEQ_LENGTH(queryString)))
        IoState_error_(IOSTATE, m, "query error(%d): %s", mysql_errno(&DATA(self)->connection), mysql_error(&DATA(self)->connection));

    if((result = mysql_store_result(conn)) && (colLength = mysql_num_fields(result))) {
        list = IoList_new(IOSTATE);

        if(useMap) {
            columnNames = (char**) malloc(colLength * sizeof(char*));
            for(c = 0; c < colLength && (column = mysql_fetch_field(result)); ++c)
                columnNames[c] = column->name;

            while((row = mysql_fetch_row(result)))
            {
                colLengths = mysql_fetch_lengths(result);
                rowObject = IoMap_new(IOSTATE);

                for(c = 0; c < colLength; ++c)
                    IoMap_rawAtPut(rowObject, IOSYMBOL(columnNames[c]), IOSEQ((unsigned char *)row[c], (size_t)colLengths[c]));

                IoList_rawAppend_(list, rowObject);
            }

            free(columnNames);
        }
        else
        {
            while((row = mysql_fetch_row(result))) {
                colLengths = mysql_fetch_lengths(result);
                rowObject = IoList_new(IOSTATE);

                for(c = 0; c < colLength; ++c)
                    IoList_rawAppend_(rowObject, IOSEQ((unsigned char *)row[c], (size_t)colLengths[c]));

                IoList_rawAppend_(list, rowObject);
            }
        }

        mysql_free_result(result);
        return list;
    }
    else
        return IONUMBER(mysql_affected_rows(conn));
}
コード例 #27
0
ファイル: _IoCairoSVGSurface.c プロジェクト: Akiyah/io
IoObject *IoCairoSVGSurface_versionToString(IoCairoSVGSurface *self, IoObject *locals, IoMessage *m)
{
	cairo_svg_version_t version = IoMessage_locals_intArgAt_(m, locals, 0);
	return IOSYMBOL(cairo_svg_version_to_string(version));
}
コード例 #28
0
ファイル: IoCoroutine.c プロジェクト: jdp/io
IoObject *IoCoroutine_rawRunMessage(IoCoroutine *self)
{
	return IoObject_rawGetSlot_(self, IOSYMBOL("runMessage"));
}
コード例 #29
0
ファイル: IoMessage.c プロジェクト: mikedouglas/io
IoMessage *IoMessage_proto(void *state)
{
	IoMethodTable methodTable[] = {
	{"clone", IoMessage_clone},

	{"name", IoMessage_protoName},
	{"setName", IoMessage_protoSetName},

	{"next", IoMessage_next},
	{"setNext", IoMessage_setNext},
	{"isEndOfLine", IoMessage_isEOL},
	{"nextIgnoreEndOfLines", IoMessage_nextIgnoreEOLs},
	{"last", IoMessage_last},
	{"lastBeforeEndOfLine", IoMessage_lastBeforeEOL},

	{"argAt", IoMessage_argAt},
	{"arguments", IoMessage_arguments},
	{"setArguments", IoMessage_setArguments},
	{"appendArg", IoMessage_appendArg},
	{"appendCachedArg", IoMessage_appendCachedArg},
	{"argCount", IoMessage_argCount_},

	{"cachedResult", IoMessage_cachedResult},
	{"setCachedResult", IoMessage_setCachedResult},
	{"removeCachedResult", IoMessage_removeCachedResult},
	{"hasCachedResult", IoMessage_hasCachedResult},

	{"lineNumber", IoMessage_lineNumber},
	{"setLineNumber", IoMessage_setLineNumber},

	{"characterNumber", IoMessage_characterNumber},
	{"setCharacterNumber", IoMessage_setCharacterNumber},

	{"label", IoMessage_label},
	{"setLabel", IoMessage_setLabel},

	{"code", IoMessage_descriptionString},
	{"doInContext", IoMessage_doInContext},
	{"fromString", IoMessage_fromString},
	{"argsEvaluatedIn", IoMessage_argsEvaluatedIn},
	{"asString", IoMessage_asString},

	{"asMessageWithEvaluatedArgs", IoMessage_asMessageWithEvaluatedArgs},

	{"opShuffle", IoMessage_opShuffle},
	{"opShuffleC", IoMessage_opShuffle},
	
	#ifdef IOMESSAGE_HASPREV
	{"previous", IoMessage_previous},
	#endif

	{NULL, NULL},
	};

	IoObject *self = IoObject_new(state);
	IoMessageData *d;
	IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoMessageData)));
	d = IoObject_dataPointer(self);

	IoObject_tag_(self, IoMessage_newTag(state));
	d->args  = List_new();
	d->name  = IOSYMBOL("[unnamed]");
	d->label = IOSYMBOL("[unlabeled]");
	//d->charNumber = -1;
	d->lineNumber = -1;
	IoState_registerProtoWithFunc_((IoState *)state, self, protoId);

	IoObject_addMethodTable_(self, methodTable);
	return self;
}
コード例 #30
0
ファイル: IoCoroutine.c プロジェクト: jdp/io
void IoCoroutine_rawSetRunLocals_(IoCoroutine *self, IoObject *v)
{
	IoObject_setSlot_to_(self, IOSYMBOL("runLocals"), v);
}