/* * __OS__: expand the name of the Host Operating System. * Our last constant is the __OS__ constant. * When the __OS__ identifier is seen in the running script, this procedure * gets called by the underlying Jx9 virtual machine. * This procedure is responsible of expanding the constant identifier to * the desired value (OS name in our case). */ static void OS_Constant(unqlite_value *pValue, void *pUserData /* Unused */ ) { #ifdef __WINNT__ unqlite_value_string(pValue, "Windows", -1 /*Compute input length automatically */); #else /* Assume UNIX */ unqlite_value_string(pValue, "UNIX", -1 /*Compute input length automatically */); #endif /* __WINNT__ */ }
unqlite_value* VirtualMachine::createUnqlite(const QVariant& var) { unqlite_value* retval = NULL; QVariant::Type type = var.type(); if (type == QVariant::Map) { retval = unqlite_vm_new_array(m_pVm); QMap<QString, QVariant> map = var.toMap(); QMapIterator<QString, QVariant> it(map); while (it.hasNext()) { it.next(); unqlite_value* pVal = createUnqlite(it.value()); if (pVal) { QString key = it.key(); const char* pKey = key.toUtf8().data(); unqlite_array_add_strkey_elem(retval, pKey, pVal); unqlite_vm_release_value(m_pVm, pVal); } else { qDebug() << "Could not create unqlite value for map"; } } } else if (type == QVariant::List) { retval = unqlite_vm_new_array(m_pVm); QList<QVariant> list = var.toList(); QListIterator<QVariant> it(list); while (it.hasNext()) { unqlite_value* pVal = createUnqlite(it.next()); if (pVal) { unqlite_array_add_elem(retval, NULL, pVal); unqlite_vm_release_value(m_pVm, pVal); } else { qDebug() << "Could not create unqlite value for list"; } } } else { retval = unqlite_vm_new_scalar(m_pVm); if (type == QVariant::Int || type == QVariant::UInt) { unqlite_value_int(retval, var.toInt()); } else if (type == QVariant::Double) { unqlite_value_double(retval, var.toDouble()); } else if (type == QVariant::Bool) { unqlite_value_bool(retval, var.toBool()); } else if (type == QVariant::String) { QByteArray bytes = var.toString().toUtf8(); unqlite_value_string(retval, bytes.data(), bytes.length()); } else { qDebug() << "Could not determine type of the given QVariant" << var; } } return retval; }