run an interpreter in an allegro game?

My idea is to make a graphical text adventure in which the user interface is an interpreter/shell (the player character is a robot). In what I have so far, the game is loaded as a module in a Tcl interpreter. So there's one window running the interpreter and then another window with the allegro game. What I'd like to have is, inside the allegro game, a textbox running the interpreter.

could anyone tell me first of all whether this is possible and, if so, give me a general idea of how to go about doing it?

Thanks so much for any ideas.


You could store your interpreter output in a string, and draw it using multiple calls to al_draw_string (once per line). Input can be handled via ALLEGRO_EVENT_KEY_CHAR events (see, for example, the ex_logo example).


You'd have to write your own textbox class, but this is certainly doable.

Your textbox class needs to keep track of the input string. Before the user presses enter, you have to build the input string, adding each keypress to it. You also have to respond to backspace by removing the last character from the input string.

If the user presses enter, you respond to that by passing the input string to the game engine.


thanks for the replies. If I understand you both right, what you are explaining is how to get text input from the user and send it to the allegro display.

What I'm not understanding is how, on the one hand, you take the output from the interpreter and make it available to, for example, al_draw_string, or, on the other hand, how you take the string that you collect from ALLEGRO_EVENT_KEY_CHAR events and send it to the interpreter to be interpreted.

In other words, once you collect the user's key presses into a string, how do you get the interpreter to evaluate that string?

I hope I'm making sense.


That's not really Allegro specific at this point, and depends on how your interpreter's API works. If you're using something like C++/Tcl then it could look something like this:

Tcl::interpreter i;

Tcl::object result = i.eval("some tcl command");

printf("%d\n", result.get<int>(i))


Thanks, SiegeLord! C++/Tcl looks to be a very helpful suggestion. I'll check it out.

roger levy

I assume the API provides a function like FoobarEvaluate().

Thread #616931. Printed from