handmade/test/test_lua.cpp

58 lines
805 B
C++
Raw Permalink Normal View History

#include "lib_lua_common.h"
#include "trim.h"
#include <iostream>
#include <fstream>
#include <string>
static const char* prompt_str = "> ";
static void my_ShowPrompt (void)
{
printf ("\n%s", prompt_str);
fflush (stdout);
}
int main (int argc, char** argv)
{
std::string buf;
bool done = false;
lua_State* L;
L = luaL_newstate ();
luaL_openlibs (L);
while (!done)
{
my_ShowPrompt ();
try
{
getline (std::cin, buf);
}
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 ());
}
lua_close (L);
return 0;
}