Example #1
0
File: io.cpp Project: rod-lin/ink
Ink_Object *InkMod_IO_Loader(Ink_InterpreteEngine *engine, Ink_ContextChain *context, Ink_Object *base, Ink_ArgcType argc, Ink_Object **argv, Ink_Object *this_p)
{
	if (!checkArgument(engine, argc, 2)) {
		return NULL_OBJ;
	}

	Ink_Object *self = argv[0];
	Ink_Object *apply_to = argv[1];
	Ink_Object **tmp_argv = (Ink_Object **)malloc(sizeof(Ink_Object *) * 2);

	Ink_Object *file_pkg = self->getSlot(engine, "file");
	Ink_Object *direct_pkg = self->getSlot(engine, "direct");

	Ink_Object *file_loader = file_pkg->getSlot(engine, "load");
	Ink_Object *direct_loader = direct_pkg->getSlot(engine, "load");

	tmp_argv[0] = file_pkg;
	tmp_argv[1] = apply_to;

	if (file_loader->type == INK_FUNCTION) {
		file_loader->call(engine, context, file_pkg, 2, tmp_argv);
	} else {
		InkWarn_Package_Broken(engine, "io.file");
		return NULL_OBJ;
	}

	tmp_argv[0] = direct_pkg;

	if (direct_loader->type == INK_FUNCTION) {
		direct_loader->call(engine, context, direct_pkg, 2, tmp_argv);
	} else {
		InkWarn_Package_Broken(engine, "io.direct");
		return NULL_OBJ;
	}

	free(tmp_argv);

	InkMod_IO_bondTo(engine, apply_to);

	return NULL_OBJ;
}
Example #2
0
Ink_Object *InkNative_Actor_Send_Sub(Ink_InterpreteEngine *engine, Ink_ContextChain *context, Ink_ArgcType argc, Ink_Object **argv, Ink_Object *this_p)
{
    Ink_Object *base = context->searchSlot(engine, "base");

    if (!checkArgument(engine, argc, argv, 1, INK_STRING)) {
        return NULL_OBJ;
    }

    Ink_Object *msg = base->getSlot(engine, "msg");
    if (msg->type != INK_STRING) {
        InkWarn_Multink_Message_is_not_a_String(engine);
        return NULL_OBJ;
    }

    Ink_InterpreteEngine *dest = InkActor_getActor(as<Ink_String>(argv[0])->getValue());
    if (!dest) {
        InkWarn_Multink_Actor_Not_Found(engine, as<Ink_String>(argv[0])->getValue().c_str());
        return NULL_OBJ;
    }

    dest->sendInMessage(engine, as<Ink_String>(msg)->getValue());

    return TRUE_OBJ;
}