wookoon
28th September 2010, 04:30
QScriptEngine engine;
QScriptValue o = engine.globalObject();
QScriptValue oo;
QScriptValue o1;
o1 = o.property("org");
if (!o1.isValid()) {
o1 = engine.newObject();
o.setProperty("org", o1);
}
o1= o.property("org.math");
if (!o1.isValid()) {
o1 = engine.newObject();
o.setProperty("math", o1);
}
engine.evaluate("org.sum = function Math_sum(a){ return 123456; }");
engine.evaluate("org.math.sum = function Math_sum(a){ return 654321; }");
engine.evaluate("var r = org.sum(12); print(r); ");
engine.evaluate("var r1 = org.math.sum(12); print(r1); ");
output is: 123456
I have try this way too:
QScriptValue o = engine.globalObject();
QScriptValue oo;
QScriptValue o1;
o1 = o.property("org");
if (!o1.isValid()) {
o1 = engine.newObject();
o.setProperty("org", o1);
}
QScriptValue o2;
o2= o1.property("math");
if (!o2.isValid()) {
o2 = engine.newObject();
o.setProperty("math", o2);
}
but the outout still is 12345.
If i want excute function org.math.sum(), how should I set the property.
QScriptValue o = engine.globalObject();
QScriptValue oo;
QScriptValue o1;
o1 = o.property("org");
if (!o1.isValid()) {
o1 = engine.newObject();
o.setProperty("org", o1);
}
o1= o.property("org.math");
if (!o1.isValid()) {
o1 = engine.newObject();
o.setProperty("math", o1);
}
engine.evaluate("org.sum = function Math_sum(a){ return 123456; }");
engine.evaluate("org.math.sum = function Math_sum(a){ return 654321; }");
engine.evaluate("var r = org.sum(12); print(r); ");
engine.evaluate("var r1 = org.math.sum(12); print(r1); ");
output is: 123456
I have try this way too:
QScriptValue o = engine.globalObject();
QScriptValue oo;
QScriptValue o1;
o1 = o.property("org");
if (!o1.isValid()) {
o1 = engine.newObject();
o.setProperty("org", o1);
}
QScriptValue o2;
o2= o1.property("math");
if (!o2.isValid()) {
o2 = engine.newObject();
o.setProperty("math", o2);
}
but the outout still is 12345.
If i want excute function org.math.sum(), how should I set the property.