How to create a script engine class in C# [duplicate]
Possible Duplicate:
Is it possible to make a call to a C# application from a C++ application?
I am playing with the idea of writing a proof of concept application that contains a script engine that runs (executes) a .CLI language (e.g. C#, VB.Net etc).
I had originally wanted to create the script engine application in C++, but that appears to be fraught with problems and work arounds. Instead, I want to write the script engine in C# instead now.
I have ske开发者_运维问答tched together a very rough idea of what it is I'm trying to do below:
The code is still pseudo C++, but hopefully, the semantics should be clear:
class GenericDotNetLangInterpreter
{
public:
Results run(const Arguments& args);
protected:
GenericDotNetLangInterpreter(const std::string &script);
};
class MyInterpreter : private GenericDotNetLangInterpreter
{
public:
MyInterpreter(const LanguageType l);
Results run(const Arguments& args);
}
Couple of questions:
Has someone done this kind of thing before, and is there some code I can use as a reference point?
what are some gotchas I need to be aware of going down this path?
Not really an answer, but pointing out that C# and VB.Net aren't interpreted, but compiled to IL (similar to Java's Bytecode). In other words, your API name and signature would probably change. You would need to invoke the associated compiler and then execute the code.
There are .Net languages that can run interpreted on the DLR, but I'm not clear on calling that from a native language.
The limit between managed and unmanaged applications is thinner than it looks. Your C++ app can link with mscorelib (basic .NET support).
From there on, your C++ app can compile your text "script" to .NET byte code and execute it.
Whether it makes sense or is a good idea is left up to you.
精彩评论