// Use this for initialization void Start() { /* * var ScriptEngine = IronPython.Hosting.Python.CreateEngine(); * // and the scope (ie, the python namespace) * var ScriptScope = ScriptEngine.CreateScope(); * * // execute a string in the interpreter and grab the variable * string example = "f = open('testfile', 'w')\nf.write('Testoutput')\nf.close()"; * * var ScriptSource = ScriptEngine.CreateScriptSourceFromString(example); * ScriptSource.Execute(ScriptScope); * string came_from_script = ScriptScope.GetVariable<string>("output"); * // Should be what we put into 'output' in the script. * Debug.Log(came_from_script); * * var ScriptEngine = IronPython.Hosting.Python.CreateEngine(); * // and the scope (ie, the python namespace) * var ScriptScope = ScriptEngine.CreateScope(); * // execute a string in the interpreter and grab the variable * string example = "from System.Collections import BitArray\nba = BitArray(5)\nba.Set(0, False)\noutput = ba[0]"; * * var ScriptSource = ScriptEngine.CreateScriptSourceFromString(example); * ScriptSource.Execute(ScriptScope); * bool came_from_script = ScriptScope.GetVariable<bool>("output"); * // Should be what we put into 'output' in the script. * Debug.Log(came_from_script); */ InputBuffer = ""; Lua.LuaOptions opts = new Lua.LuaOptions(); opts.ExecuteHandler = ExecuteHandler; StdIn = new NixStream(); opts.StdIn = StdIn; //stdin.Write ("Melli\n"); /*Thread t = new Thread(() => * { * Thread.Sleep(2000); * //Console.WriteLine("Waiting for use input: "); * //string input = Console.ReadLine(); * //stdin.Write(input + "\n"); * stdin.Write("Melli\n"); * }); * t.Start();*/ Thread t2 = new Thread(() => { Lua l = new Lua(opts); l.DoString(@"os.execute('hello: ') s = io.read('*l') os.execute('how are you? '..s)" ); }); t2.Start(); }
public LuaSystem(Session session, NixSystem system, Stream stdOut, Stream stdIn, Stream stdErr) { MainSession = session; MainSystem = system; StdOut = stdOut; StdIn = stdIn; StdErr = stdErr; Lua.LuaOptions opts = new Lua.LuaOptions(); opts.StdOut = stdOut; opts.StdIn = stdIn; opts.StdErr = stdErr; opts.ExecuteHandler = ExecuteHandler; opts.OpenFileHandler = OpenFileHandler; opts.RenameFileHandler = RenameFileHandler; opts.RemoveFileHandler = RemoveFileHandler; opts.GetTempFilenameHandler = GetTempFilenameHandler; Lua = new Lua(opts); }