dynamic language runtime - How to redirect the input of ironruby to a textbox (WinForms & Silverlight 4) -
dynamic language runtime - How to redirect the input of ironruby to a textbox (WinForms & Silverlight 4) -
i'm building ironruby console in silverlight 4 , winforms (net4). can redirect output without problems:
myruntime = ruby.createruntime(); msoutput = new memorystream(); myruntime.io.setoutput(msoutput, encoding.utf8); myengine = myruntime.getengine("rb"); mysource = myengine.createscriptsourcefromstring("a='123'\nputs a", sourcecodekind.statements); mysource.execute(); textbox2.text = readfromstream(msoutput);
now, want redirect input also, getting 'nil' script:
myruntime = ruby.createruntime(); msoutput = new memorystream(); msinput = new memorystream(); myruntime.io.setoutput(msoutput, encoding.utf8); myruntime.io.setinput(msinput, encoding.utf8); myengine = myruntime.getengine("rb"); mysource = myengine.createscriptsourcefromstring("a=gets\nputs a", sourcecodekind.statements); byte[] bytearray = encoding.utf8.getbytes("123"); msinput.write(bytearray, 0, bytearray.length); mysource.execute(); textbox2.text = readfromstream(msoutput);
i cannot find samples of redirecting input, can please send example? give thanks you.
i don't have sample code available instead of using memorystream need implement stream. when reads on stream occur need send "contents" of text box stream. you'll need mechanism determining when send contents - e.g. when user hits return. you'll need setup thread blocking reads , utilize autoresetevent block until text box signals input complete.
ironruby dynamic-language-runtime sample
Comments
Post a Comment