How to use a language to program instances of class?

Hello!

I begin to make a game creator for myself. I want to use c++ for the engine (work in progress), and made the gui in C# or Java (WIP too...). But what I want some kind of scripting language, what let me add new codes to the instance. I thinking about something like Game Maker or RPG Maker. How can I add extra code to instances to a class like this? I thinking about storing them in strings and store the Instances in xml files, and when I build the game, somehow turn the strings into code, and add them to the compiling. Any idea?

Thanks for your help!
google class factory. I think, but am not sure, if this is what you seek.
They work to a point, but I have found that code generation to c++ is usually poor. For this reason a lot of bot-code generators use a simple language like C instead. It depends on the scope of the problem ... the bigger the problem, the worse the bots tend to do.

A class factory has nothing to do with code interpretation or run-time code generation.

OP, since you're already using C# or Java, those languages already have run-time compilers available for them. With Java, I believe the compiler is by default part of the standard library. With C# you need to include a Mono DLL to add the compiler to your program.
Then to execute the dynamic code you'll basically do something like
1
2
3
4
5
6
7
void execute(string code){
    Compiler compiler = new Compiler();
    CompiledCode cc = compiler.compile(code);
    DynamicClass dc = cc.load();
    ExecutableCode ec = dc.NewInstance();
    ec.execute();
}
Last edited on
Topic archived. No new replies allowed.