示例#1
0
static JSBool
perlarray_set(
    JSContext *cx,
    JSObject *obj,
    jsval id,
    jsval *vp
) {
    dTHX;
    SV *ref = (SV *)JS_GetPrivate(cx, obj);
    AV *av = (AV *)SvRV(ref);

    PJS_ARRAY_CHECK

    if(JSVAL_IS_INT(id)) {
        IV ix = JSVAL_TO_INT(id);
        SV *sv;
        if(!PJS_ReflectJS2Perl(aTHX_ cx, *vp, &sv, 1)) {
            JS_ReportError(cx, "Failed to convert argument to Perl");
            return JS_FALSE;
        }
        if(!av_store(av, ix, sv)) {
	    if(SvRMAGICAL(av)) mg_set(sv);
	    sv_free(sv);
	}
    }
    
    return JS_TRUE;
}
示例#2
0
static JSBool
perlarray_unshift(
    JSContext *cx,
    JSObject *obj,
    uintN argc,
    jsval *argv,
    jsval *rval
) {
    dTHX;
    SV *ref = (SV *)JS_GetPrivate(cx, obj);
    AV *av = (AV *)SvRV(ref);
    IV tmp;

    PJS_ARRAY_CHECK

    if(argc) {
        av_unshift(av, argc);
        for(tmp = 0; tmp < argc; tmp++) {
            SV *sv;
            if(!PJS_ReflectJS2Perl(aTHX_ cx, argv[tmp], &sv, 1)) {
                JS_ReportError(cx, "Failed to convert argument %d to Perl", tmp);
                return JS_FALSE;
            }
            if(!av_store(av, tmp, sv)) {
		if(SvRMAGICAL(av)) mg_set(sv);
		sv_free(sv);
	    }
        }
    }
    
    return JS_TRUE;
}
示例#3
0
static void 
foreach_fn_property(gpointer key_p, gpointer value_p, gpointer user_data_p)
{
    char       *key = key_p;
    property_t *property = value_p;
    GSList     *value;
    HV         *hv = user_data_p;
    AV         *list = newAV();
    HV         *property_hv = newHV();
    SV         *val;

    hv_store(property_hv, "append", strlen("append"), newSViv(property->append), 0);
    hv_store(property_hv, "priority", strlen("priority"), newSViv(property->priority), 0);
    for(value=property->values; value != NULL; value = value->next) {
	av_push(list, newSVpv(value->data, 0));
    }
    hv_store(property_hv, "values", strlen("values"), newRV_noinc((SV*)list), 0);

    val = newRV_noinc((SV*)property_hv);
    hv_store(hv, key, strlen(key), val, 0);
    mg_set(val);
    SvREFCNT_dec(val);
}