Exemple #1
0
template <> const QMetaObject *Conversion<const QMetaObject *>::from(RubyValue x)
{
    if (x == RubyValue()) {
        return nullptr;
    }
    return wrapperRubyClass<Ext_MetaObject>().unwrap(x)->metaObject();
}
Exemple #2
0
template <> QDateTime Conversion<QDateTime>::from(RubyValue time)
{
    int offset;

    if (time.isKindOf(rb_cTime)) {
        offset = time.send(RUBYQML_INTERN("gmt_offset")).to<int>();
    } else { // DateTime
        VALUE dayOffset = time.send(RUBYQML_INTERN("offset"));
        offset = RubyValue(RRATIONAL(dayOffset)->num).to<int>() * 24 * 60 * 60 / RubyValue(RRATIONAL(dayOffset)->den).to<int>();
        time = time.send(RUBYQML_INTERN("to_time"));
    }
    timeval at = rb_time_timeval(time);

    QDateTime dateTime;
    dateTime.setOffsetFromUtc(offset);
    dateTime.setMSecsSinceEpoch(at.tv_sec * 1000 + at.tv_usec / 1000);
    return dateTime;
}
SimSpark::RubyValue SimSpark::GetScriptValue(const std::string& name) const
{
    for (auto it = mScriptValues.begin(); it != mScriptValues.end(); it++)
    {
        if (it->first.compare(name) == 0)
        {
            return it->first;
        }
    }
    return RubyValue();
}