2022-01-02 19:28:16 -05:00
|
|
|
#include "lib_lua_common.h"
|
2022-01-09 23:37:48 -05:00
|
|
|
#include "trim.h"
|
2022-01-02 19:28:16 -05:00
|
|
|
|
2022-01-09 23:37:48 -05:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
2022-01-02 19:28:16 -05:00
|
|
|
|
2022-01-09 23:37:48 -05:00
|
|
|
static const char* prompt_str = "> ";
|
|
|
|
|
|
|
|
static void my_ShowPrompt (void)
|
2022-01-02 19:28:16 -05:00
|
|
|
{
|
2022-01-09 23:37:48 -05:00
|
|
|
printf ("\n%s", prompt_str);
|
|
|
|
fflush (stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main (int argc, char** argv)
|
|
|
|
{
|
|
|
|
std::string buf;
|
|
|
|
bool done = false;
|
|
|
|
|
2022-01-02 19:28:16 -05:00
|
|
|
lua_State* L;
|
|
|
|
L = luaL_newstate ();
|
|
|
|
luaL_openlibs (L);
|
2022-01-09 23:37:48 -05:00
|
|
|
|
|
|
|
while (!done)
|
2022-01-02 19:28:16 -05:00
|
|
|
{
|
2022-01-09 23:37:48 -05:00
|
|
|
my_ShowPrompt ();
|
|
|
|
try
|
2022-01-02 19:28:16 -05:00
|
|
|
{
|
2022-01-09 23:37:48 -05:00
|
|
|
getline (std::cin, buf);
|
2022-01-02 19:28:16 -05:00
|
|
|
}
|
2022-01-09 23:37:48 -05:00
|
|
|
catch (std::ifstream::failure& e)
|
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (std::cin.eof ())
|
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf = trim (buf);
|
|
|
|
if (buf.empty ())
|
|
|
|
{
|
|
|
|
std::cin.clear();
|
|
|
|
std::cin.ignore();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
printf (" => ");
|
|
|
|
fflush (stdout);
|
|
|
|
common_lua_run (L, "line", buf.c_str (), buf.length ());
|
2022-01-02 19:28:16 -05:00
|
|
|
}
|
2022-01-09 23:37:48 -05:00
|
|
|
|
2022-01-02 19:28:16 -05:00
|
|
|
lua_close (L);
|
|
|
|
return 0;
|
|
|
|
}
|