本文介绍了如何在运行时将字符串转换为代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在生成包含 if else 表达式的字符串.我想知道我是否可以在运行时执行此表达式?这是一个示例:
I am generating strings containing if else expressions. I was wondering if I can execute this expressions at run time? Here's an example:
string s = "if(x > 10) {Fly = true;} else {Fly = False;}"; Execute (s);是否有可能做到这一点?
Is it even possible to do this?
推荐答案可以使用TCC( bellard/tcc/).它允许在运行时本地编译和运行代码.另一种方法是使用解释器,那里有很多(LUA,Python等,请参见列表 wiki ).
It is possible to use TCC ( bellard/tcc/ ). It allows to compile and run code natively at runtime. Another approach is to use an interpreter, there are plenty out there (LUA, Python etc, see list wiki).
更多推荐
如何在运行时将字符串转换为代码
发布评论