Interactive lua prompt in opengl application

Ok, so when I run lua I get something like:

lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> 

      

Now I want a prompt like this, 1) in a graphics application that I wrote.

My GUI application can provide functions like: get_input_from_screen (); and write_this_crap_out_to_screen (); and more functions I can write as needed

I also know how to embed a lua interpreter in my C ++ code (short tutorial on the web)

What I don't know ... how to connect the lua interpreter I / O with my GUI file.

Any help / links are appreciated.

Thanks!

+2


a source to share


3 answers


Why don't you take a look at the source code of the stand-alone Lua interpreter (lua.c) and see how Reoberto , et al. did this?



+3


a source


I wanted to do something like this too, and just viewing lua.c wasn't really a 'click' for me. It was only when I read somewhere that you want to implement / overwrite the print () function with your own that everything makes sense to me.

The key is to write your own print function in your application that knows how to send the lua output to the component you want - be it a TextBox widget, a scripting console for games, another file, or whatever you have. Then all you have to do is register this print function so lua knows about it.



Likewise, to get lua to handle script input, create a function that fetches a string for processing (like a widget's textbox), then pass that string to something like lual_dostring () or similar. Then set the input function to fire on some event like when the user presses the enter button or when the button is pressed, etc.

This site has a very good example code here to illustrate.

+1


a source


The logic would look like this, I suppose.

string s = gui_read();
string result = lua_interpreter(s);
gui_print(result);

      

0


a source







All Articles