Evaluate Variables in QtScript
-
I am looking for a way to find out the variables in a script (QtScript).
An example would be this formula:
@c = a + b + 15@The variables I would like to find is a, b and c.
Can someone give me a hint with this?
-
I think you are looking for how to solve an equation using JavaScript - something very different from evaluating script, such as the QtScript engine does.
The problem you pose has more than one solution as well, as you can see here: "Wolfram Alpha":http://www.wolframalpha.com/input/?i=c+=+a+++b+++15 (sorry you have to enter the equation again as this forum destroys it).
Some solutions for your equation would be
25 = 5 + 5 + 15
35 = 10 + 10 + 15and so on.
-
Thanks for your input, but my equation was just a sample.
What I want is as example to load this equation from a file, but I would like to find out the used variables before putting it into the script engine.
-
Hello,
OK now I get it - you are not looking for variable values but variable names.
Do you have a real-world example of what you want to achieve?
-
I do not have a real world example, but I try to explain it more global.
Let's assume I can get script-code in several ways (file, tcp, ...) and I want to execute this code in the script engine. Before executing the code I would like to get somehow a list of used variables.
The question is now, how to get the list of variables?
-
Parse the code. Either with an own parser or by using some ECMAScript parser library. Maybe you can somehow rip out the parsing code of the QtScript module.
-
Okay, but it seems there is no way that the QtScript could do this?