-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdemo_repl.cxx
More file actions
33 lines (25 loc) · 797 Bytes
/
demo_repl.cxx
File metadata and controls
33 lines (25 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include "lua_interpreter.hxx"
using namespace luai;
int main() {
auto state = lua_interpreter{};
state.openlibs();
auto line = std::string{};
auto linenum = long{1};
std::cout << "Lua REPL version: " << state.lua_version << "\n\n" << std::flush;
while (true) {
std::cout << "in [" << linenum << "] " << std::flush;
read:
if (!std::getline(std::cin, line))
break;
if (line.size() == 0)
goto read;
std::cout << "out [" << linenum << "] " << std::endl;
auto ret = state.run_chunk(line.c_str());
// error occured
if (!std::get<0>(ret))
std::cerr << "error: " << std::get<1>(ret) << std::endl;
std::cout << std::endl;
++linenum;
}
}