c++ - Converting string to regular function

Started by
5 comments, last by Zahlman 15 years, 9 months ago
Hi all, is there any way to convert standart text variable (for example: char Text[1024]) to function? Of course assuming that text variable contains full function code. Or, if text variable contains function code how to call it? Thanks for any suggestions!
Advertisement
Not short of including a compiler with your program and calling the compiler at runtime. Consider instead using a scripting language like Python, Lua or Angelscript.
Yes there is.

What are you trying to accomplish? Exact solution depends on many factors.
I want to use it in DirectX FX files - each FX file (as a shader container) needs special processing (code) and I want to put that code in the FX file as a string and at runtime get that string and execute it just before starting the effect.
You'll want to use some kind of scripting language for this; if the nature of the prologue code you're putting in the .fx file is very simple, you may be able to simply hand-roll your own crude 'interpreted language' and use that. Otherwise you may need to look in to embedding something like Lua. You could do this with C++, too, but it would be extremely cumbersome (you'd need to host yourself a compiler, et cetera).

It seems like you're trying to take a code-driven approach to what should be data-driven, however. That is, you want to write code to do some effect-specific setup that you should perhaps attempt to generalize into a data-driven model. What kind of things do you see this prologue code doing for you?
One thing you might be able to do is instead of putting C++ code into the fx file you'd put the fx file in with the C++ code, as a string, and load them as a DLL - something akin to Yann's shaders.
Quote:Original post by jpetrie
What kind of things do you see this prologue code doing for you?


Quoted for emphasis. The best design choice really hinges on this question.

This topic is closed to new replies.

Advertisement