我制作了一种非常基本的脚本语言 - 我希望能够读取输出。
我制作了一种非常基本的脚本语言,在我的语言中有一个名为 print
的命令 - 或者换句话说 - print _k
应该以某种方式显示 _k
> 给用户。
到目前为止,我一直在使用 MessageBox.Show,但我还想为我的语言添加一个调试器,并且出于其他原因,我想使用 Stream 或类似的东西。
基本上,在主窗体上,我想要一个 TextBox
或以某种方式连接到 Stream
的东西,以及何时(在脚本中,在不同的线程上)打印调用某事
时,它将在我的表单上引发一个事件,该事件将在我的TextBox
上写入something
。
我曾经通过发送 TextBox
对象作为参数来克服这个问题,但我想让它更加动态(这样我就可以用比 TexBox
更多的方式读取数据)。
不幸的是,Stream
没有任何我可以使用的事件。
也许还有另一种动态方式?
I made a very basic scripting language, and in my language there is a command called print
- or in other words - print _k
should somehow show _k
to the user.
I was using MessageBox.Show
till now but I also want to include a debugger for my language and for other reasons, I want to use a Stream
or something like it.
Basically, on the main form I wanna have a TextBox
or something that is somehow connected to a Stream
, and when (in script, on a different thread) print something
is called it will raise an event on my form that will write something
on my TextBox
.
I used to overcome this problem by sending the TextBox
object as a parameter, but I want to make it more dynamic (so I could read data in more ways than TexBox
).
Unfortunately, Stream
doesn't have any events I can use.
Maybe there is another dynamic way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能会帮助您:
http://saezndaree.wordpress.com/2009/03/29/how-to-redirect-the-consoles-output-to-a-textbox-in-c/
This might help you out:
http://saezndaree.wordpress.com/2009/03/29/how-to-redirect-the-consoles-output-to-a-textbox-in-c/
恭喜构建了脚本语言;我曾经这样做过一次,这是我所做过的最有趣和最富有成效的事情之一。您提供调试器并使用流而不是字符串或文件的本能是好的。
由于您没有提供代码,因此很难建议如何解决您的具体问题,因此我们必须猜测。我通过在所有 API 中传递 Stream 来处理这种情况,并通过将文本框文本转换为 MemoryStream 并在中使用 StreamReader 来处理文本框。脚本引擎。
顺便说一句,代码项目有一个关于创建名为 ConScript,配有包含调试器的 IDE。我从这个系列中得到了很多想法。
Congratulations on building a scripting language; I did that once and it was one of the most fun and productive things I worked on. Your instincts to provide a debugger and to use streams rather than strings or files are good ones.
It is difficult to suggest how to approach you specific problem because you provide no code, so we have to guess. I handled that situation by passing
Stream
s in all APIs, and handled text boxes by converting the textbox text to aMemoryStream
, and usingStreamReader
in the scripting engine.As an aside, The Code Project had an outstanding series on creating a scripting language called ConScript, complete with an IDE including a debugger. I got a lot of ideas out of that series.