File indexing completed on 2024-04-14 16:00:15
0001 #include "util.h" 0002 0003 #include <QDebug> 0004 #include <QUrl> 0005 0006 #ifdef EMSCRIPTEN 0007 #include <emscripten/val.h> 0008 #include <emscripten.h> 0009 #endif 0010 0011 #ifdef EMSCRIPTEN 0012 0013 EMSCRIPTEN_KEEPALIVE 0014 void sayHi() { 0015 printf("Hi!\n"); 0016 } 0017 0018 #endif 0019 0020 QString Util::code() const 0021 { 0022 return _code; 0023 } 0024 0025 std::string Util::codeEMS() const 0026 { 0027 return _code.toStdString(); 0028 } 0029 0030 void Util::setCode(const QString& code) 0031 { 0032 if (_code != code) { 0033 _code = code; 0034 emit codeChanged(); 0035 } 0036 } 0037 0038 void Util::setCodeEMS(const std::string& code) 0039 { 0040 setCode(QString::fromStdString(code)); 0041 } 0042 0043 QObject* Util::qmlSingletonRegister(QQmlEngine* engine, QJSEngine* scriptEngine) 0044 { 0045 Q_UNUSED(engine) 0046 Q_UNUSED(scriptEngine) 0047 0048 return self(); 0049 } 0050 0051 Util* Util::self() 0052 { 0053 static Util* self = new Util(); 0054 return self; 0055 } 0056 0057 Util::~Util() {} 0058 0059 #ifdef EMSCRIPTEN 0060 0061 #include <emscripten/bind.h> 0062 0063 EMSCRIPTEN_BINDINGS(util) { 0064 emscripten::class_<Util>("Util") 0065 .function("code", &Util::codeEMS) 0066 .function("setCode", &Util::setCodeEMS); 0067 emscripten::function("self", &Util::self, emscripten::allow_raw_pointers()); 0068 } 0069 0070 #endif