2

I would like to

string expression = "2+2";

public string evaluateExpresion(expression)
{
   return executeJavascript(expression); // Magic javascript executor
}

Debug.Log(evaluateExpression(expression); 

How can I accomplish this?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
PandemoniumSyndicate
  • 2,855
  • 6
  • 29
  • 49

1 Answers1

1

You can create a javascript file with your desired functions and you can call them in your c# files if I don't misunderstand what you mean. In your example you can create:

// JavaScriptExpressions.js

function executeExpression( x : string ) {
    // Some code here..
}

JavaScript file and you can access the function by dragging js to the same transform with your c# file or you can drag it to a different transform. Or you can set it static if it is not connected to mono library. Here is the sample code for c#:

// YourCsharp.cs
string expression = "2+2";

public string evaluateExpresion(string expression) { 
    return transform.GetComponent<JavaScriptExpressions>().executeExpression(expression);
}

Debug.Log(evaluateExpression(expression));
kgd
  • 1,666
  • 2
  • 11
  • 15