mardi 24 octobre 2017

How do I convert a string into an executable line of code in objective-c

i know this question might be duplicate. i searched and tested a lot of code samples and librarys but still no good results.

the question is i want to do something like this in objective-c (ios): (its the idea , not the exact syntax)

NSString *Cmd=@" if (10>5) NSLog(@"Test");  ";
MyClass.Run(Cmd);

i expect that "Test" appear in Output Log.

after Researches, i Ended Up with these 2 libraries for compile in runtime:

1- libClang framework and clang_Cursor_Evaluate function .

http://ift.tt/1aSP7Dk

http://ift.tt/2yJIxCO

2-objc-eval framework .

http://ift.tt/2yOxmej

i could not do anything with libClang. and left it alone for now.

but with the secound one , i successfully compiled the framework and actualy used it in a simple project, however still no proper output!

#import <Foundation/Foundation.h>
#import "OEEvaluation.h"
void main()
{
Code1:OEEvaluation *evaluation = [OEEvaluation evaluationWithCode:@"retun @\"Hello World!\" ;" delegate:nil];
Code2://OEEvaluation *evaluation = [OEEvaluation evaluationWithCode:@"NSLog(@\"Hello World!\");" delegate:nil];
NSLog([evaluation evaluateSynchronously]);
NSLog(@"Test");
}

no output with Code1 and Code 2 . no (null) , no error, no hint.. nothing at all.

code 1 is the exact sample of the framework

maybe im wrong but i think the solutions i found are the closest Once to the answer between my researches.

now the questions are:

1- what is your suggestion to accomplish this idea (convert a string into an executable line of executable code)?

2-how to get the objc-eval.framework to work?

any tips,tuts, hints, link , sample code and guide will be appreciated. sorry for my bad english. thank you





Aucun commentaire:

Enregistrer un commentaire