MExec Function |
Namespace: XSharp.RT
Tip |
---|
In Visual Objects the return value of MCompile() is a specially formatted string with PCode tokens.
We have changed that in X#, and the return value of MCompile() is now a codeblock of the _Codeblock type. If the string that was compiled in Visual Objects was in the form of "{||.....}" then you hed to call MExec() to convert the string into a _Codeblock object. To evaluate the codeblock you would then have to pass the result of MExec() into the EVal() function. If the string that was compiled in Visual Objects was not in the form of "{||.....}", like in the examples of this topic then calling MExec() on return value of MCompile() would immediately evaluate the expression and return the result. Since in X#the return the return value of MCompile() is a codeblock of the _Codeblock type, you can you can also use the Eval() function to evaluate the codeblock. In X# Calling MExec() on the codeblock returned from MCompile() will either directly evaluate the codeblock (when the original string was not in the codeblock format) or will simply return the same codeblock when the original string was in the codeblock format. |
1LOCAL cComp AS CodeBlock // Note that this had to be string in Visual Objects 2cComp := MCompile("2+3") 3? MExec(cComp) // 5 4nResult := MExec(cComp) // Assigning 5? MExec(cComp) = 5 // Comparing 6MEMVAR Two // Declare and initialize a Private variable 7Two := 2 8cComp := MCompile("Two+3") // Macro refers to the private variable 9? MExec(cComp) // 5 10// The followin works in X# only, since the result of cComp is now a CodeBlock 11? Eval(cComp)