Example #1
0
static int sqlite_callback_return(Value v, sqlite3_context *ctx)
{
    const RefNode *r_type = fs->Value_type(v);
    if (r_type == fs->cls_int) {
        int err = FALSE;
        int64_t i64 = fs->Value_int64(v, &err);
        if (err) {
            fs->throw_errorf(mod_sqlite, "SQLiteError", "'INTEGER' out of range (-2^63 - 2^63-1)");
            return FALSE;
        }
        sqlite3_result_int64(ctx, i64);
    } else if (r_type == fs->cls_bool) {
        int i32 = Value_bool(v);
        sqlite3_result_int(ctx, i32);
    } else if (r_type == fs->cls_float) {
        double dval = Value_float2(v);
        sqlite3_result_double(ctx, dval);
    } else if (r_type == fs->cls_str) {
        RefStr *s = Value_vp(v);
        sqlite3_result_text(ctx, s->c, s->size, SQLITE_TRANSIENT);
    } else if (r_type == fs->cls_bytes) {
        RefStr *s = Value_vp(v);
        sqlite3_result_blob(ctx, s->c, s->size, SQLITE_TRANSIENT);
    } else if (r_type == fs->cls_null) {
        sqlite3_result_null(ctx);
    } else {
        fs->throw_errorf(fs->mod_lang, "TypeError", "Bool, Int, Float, Str, Bytes or Null required but %n", r_type);
        return FALSE;
    }
    return TRUE;
}
Example #2
0
static int textio_new(Value *vret, Value *v, RefNode *node)
{
    RefTextIO *tio;
    RefCharset *cs = Value_vp(v[2]);
    Ref *r = ref_new(fs->cls_textio);
    *vret = vp_Value(r);

    tio = buf_new(NULL, sizeof(RefTextIO));
    r->v[INDEX_TEXTIO_TEXTIO] = vp_Value(tio);
    r->v[INDEX_TEXTIO_STREAM] = Value_cp(v[1]);

    tio->in.ic = (void*)-1;
    tio->out.ic = (void*)-1;
    tio->cs = cs;
    tio->trans = FALSE;

    if (fg->stk_top > v + 3 && Value_bool(v[3])) {
        tio->trans = TRUE;
    }
    if (fg->stk_top > v + 4) {
        r->v[INDEX_TEXTIO_NEWLINE] = Value_cp(v[4]);
    }

    return TRUE;
}
Example #3
0
static int load_image_gif(Value *vret, Value *v, RefNode *node)
{
    RefImage *image = Value_vp(v[1]);
    int info_only = Value_bool(v[3]);

    if (!load_gif_sub(image, v[2], info_only)) {
        return FALSE;
    }
    return TRUE;
}
Example #4
0
/**
 * 検索して見つかった場合/見つからなかった場合は
 * 1.true/falseを返す
 * 2.index/nullを返す
 */
int map_index_of(Value *vret, Value *v, RefNode *node)
{
    RefMap *rm = Value_vp(*v);
    int ret_index = FUNC_INT(node);
    Value v1 = v[1];
    RefNode *type = Value_type(v1);
    int i;

    RefNode *fn_eq = Hash_get_p(&type->u.c.h, fs->symbol_stock[T_EQ]);
    if (fn_eq == NULL) {
        throw_error_select(THROW_NO_MEMBER_EXISTS__NODE_REFSTR, type, fs->symbol_stock[T_EQ]);
        return FALSE;
    }

    rm->lock_count++;
    for (i = 0; i < rm->entry_num; i++) {
        HashValueEntry *ep = rm->entry[i];
        for (; ep != NULL; ep = ep->next) {
            Value va = ep->val;

            if (Value_type(va) == type) {
                if (type == fs->cls_str) {
                    if (refstr_eq(Value_vp(v1), Value_vp(va))) {
                        break;
                    }
                } else {
                    Value_push("vv", v1, va);
                    if (!call_function(fn_eq, 1)) {
                        goto ERROR_END;
                    }
                    fg->stk_top--;
                    if (Value_bool(*fg->stk_top)) {
                        unref(*fg->stk_top);
                        if (ret_index) {
                            *vret = Value_cp(ep->key);
                        } else {
                            *vret = VALUE_TRUE;
                        }
                        return TRUE;
                    }
                }
            }
        }
    }
    if (!ret_index) {
        *vret = VALUE_FALSE;
    }

    rm->lock_count--;
    return TRUE;
ERROR_END:
    rm->lock_count--;
    return FALSE;
}
Example #5
0
static int markdown_enable_tex(Value *vret, Value *v, RefNode *node)
{
    Ref *r = Value_vp(*v);
    Markdown *md = Value_ptr(r->v[INDEX_MARKDOWN_MD]);
    if (fg->stk_top > v + 1) {
        md->enable_tex = Value_bool(v[1]);
    } else {
        *vret = bool_Value(md->enable_tex);
    }
    return TRUE;
}
Example #6
0
static int textio_next(Value *vret, Value *v, RefNode *node)
{
    Ref *ref = Value_ref(*v);

    if (!textio_gets_sub(vret, ref, TRUE)) {
        return FALSE;
    }
    if (!Value_bool(*vret)) {
        throw_stopiter();
        return FALSE;
    }
    return TRUE;
}