如何在运行时将字符串转换为代码

编程入门 行业动态 更新时间:2024-10-27 16:33:05
本文介绍了如何在运行时将字符串转换为代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在生成包含 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).

更多推荐

如何在运行时将字符串转换为代码

本文发布于:2023-11-12 07:52:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580927.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   字符串   时将   代码   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!