User entry for a class file

Hello there.

I am a Taiwanese and because my poor English that may hard to understand my question so I’m sorry about that first.
I want to build a game for teaching JavaScript, because I am a student that’s something like my assignment.
This game provide a blank block that user can type their code in it. And the game objects will act by that.

I want to know if it is possible that get the entry of user, and execute it like a js file.
e.g. a whole class file type from user.

I have found some question for that as follow:

And I wonder if that is actually what I want.

Thanks you guys for reading my question. I’m waiting for your answers.

update 5/28/2015

if (GUI.Button(Rect(600,10,50,50),btnTexture))
{
    if (!System.IO.File.Exists ("../tryFile.js")) 
    {
       stringToEdit = "You don't have such file like that";
    }
    else
    {
        AssetDatabase.ImportAsset("../tryFile.js",ImportAssetOptions.ForceSynchronousImport);
    }
 	     	
    try
    {
        object.AddComponent.<tryFile>();
    }
    catch(err)
    {
        stringToEdit = err.Message;
    }
}

I make a textArea and after I finished my class code in it, I click an button and then it will write a js file by StreamWriter.

And then I click this texture button. It checks if the file is exist. Then use AssetDatabase.ImportAsset to load theFile.

Then I try to add that js file as a component of a gameObject which name is “object”.

And it cause a compile time error (of course).

I just want to know is there has any way to solve it T_T.

----------update 5/28/2015

It’s the compile error message:

Assets/TextBoxCreator.js(37,38): BCE0018: The name ‘testjs’ does not denote a valid type (‘not found’).

And it is my whole code:

#pragma strict

var stringToEdit : String = "Hello World";
var btnTexture : Texture;
var object : GameObject;

function Awake()
{
	object = GameObject.Find("testObject");
}

function OnGUI () 
{
	// Make a text field that modifies stringToEdit.
	stringToEdit = GUI.TextArea (Rect (10, 10, 500, 500), stringToEdit, 1000);
	
	if (!btnTexture) 
	{
		Debug.LogError("Please assign a texture on the inspector");
		return;
	}
	if (GUI.Button(Rect(600,10,50,50),btnTexture))
	{
		if (!System.IO.File.Exists ("../Assets/tring/testjs.js")) 
   	    {
 
        	stringToEdit = "You don't have such file like that";
     	}
     	else
     	{
     		AssetDatabase.ImportAsset("../Assets/tring/testjs.js",ImportAssetOptions.ForceSynchronousImport);
     		stringToEdit = "import sucess?

";
}

     	try
     	{
     		object.AddComponent.<testjs>();
     	}
     	catch(err)
     	{
     		//AssetDatabase.ImportAsset
     		stringToEdit = err.Message;
     	}
     }
	if (GUI.Button(Rect(600,70,50,30),"Click"))
	{
		//create Folder
   	    if (!System.IO.Directory.Exists ("../Assets/tring")) 
   	    {
 
        	System.IO.Directory.CreateDirectory ("../Assets/tring");
     	}

     	System.IO.File.WriteAllText("../Assets/tring/testjs.js",stringToEdit);
     	
     	stringToEdit = "export sucess?

";
}
}

Hope there has anyway to do itT_T

Okay, it seems like I wasn’t quite sure what I was talking about.

There is a built-in eval() function, and you might be able to do what you want with it. Check out this answer.

Also note that this will only work in webplayer, and webplayer is about to die a slow death, as browsers start dropping plugin support.