在运行时运行任意代码 [英] Running arbitrary code at runtime

查看:99
本文介绍了在运行时运行任意代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个奇怪的问题,但我想知道这是否可能.是否有任何方法可以在运行时运行代码(由用户键入)?例如,假设我允许用户键入一些Core Graphics绘图代码.我希望此代码在预览窗格的drawRect方法中运行.

I know this is an odd question, but I'm wondering if this is possible. Is there any method by which code (which would be typed by a user) could be run during runtime? For example, suppose I would allow the user to type in some Core Graphics drawing code. I would want this code to be run in a drawRect method of my preview pane.

所以我要做的就是将这组字符串转换为实际的运行时代码.

So what I would have to do would be to convert this group of strings into actual runtime code.

这是否有可能,还是我只是在浪费时间?

Is this even possible, or am I just wasting my time?

推荐答案

我看到一些解决方案:

  1. 创建自己的语言,并在应用程序中对其进行解析
  2. 如果在Mac上,从理论上讲,您可以从它们输入的内容中创建一个函数存根,然后使用应用程序附带的GCC在运行时将代码编译为dylib,然后使用dylib函数运行您创建的函数.

这篇关于在运行时运行任意代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆