eval在Objective-C中 [英] eval in Objective-C

查看:182
本文介绍了eval在Objective-C中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在Objective-C 2.0中有什么像Matlab的eval语句吗?

在Objective-C中有没有eval函数(如lisp,javascript,python,ruby ...)?

Is there an eval function (as in lisp, javascript, python, ruby...) in Objective-C?

我的意思是eval是一个函数,可以将任意的Objective-C代码(可能有类定义,副作用,instrospection等)作为字符串(不是块或NSInvocation或IMP或某事像这样),并评估每个表达式,尊重当前运行时环境状态,副作用,类定义等。

What I mean by eval is a function that can take in arbitrary Objective-C code (possibly having class definitions, side effects, instrospection, etc) as a string (not a block or an NSInvocation or IMP or something like that), and evaluate each expression, respecting the current runtime environment state, side effects, class definitions, etc.

如果不是,是否可以在范围内实现的现有运行时间?

If not, is it possible to implement within the confines of the existing runtime?

推荐答案

语言和Apple的框架都不直接支持这样的事情。但是, LLVM 的目标之一是嵌入式编译器套件。我很确定它可以直接在内存中生成可执行代码。很难的部分是提供该代码访问调用代码的预先存在的环境。例如,编译引用本地变量的代码或类似的东西。

Neither the language nor Apple's frameworks directly support such a thing. However, one of the goals of LLVM is to be an embeddable compiler suite. I'm pretty sure it can generate executable code right into memory. The hard part would be providing that code with access to the pre-existing environment of the calling code. For example, compiling code which references a local variable or something like that.

(请注意,这种方法对于iOS App Store来说是禁止的,但也可能是可行的在Mac OS X上。)

(Mind you, this approach is forbidden for the iOS App Store, but it could maybe be workable on Mac OS X.)

这篇关于eval在Objective-C中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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