ここでは絶対的なミニマリズムを目指します。(Lua C API を使用するのは久しぶりです。)
#include <lua.hpp>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char** argv)
{
lua_State* state = luaL_newstate();
luaL_openlibs(state);
string input;
while (getline(cin, input))
{
auto error = luaL_dostring(state, input.c_str());
if (error)
{
cerr << "Lua Error: " << lua_tostring(state, -1) << '\n';
lua_pop(state, 1);
}
}
lua_close(state);
return 0;
}
このプログラムは、完璧な Lua を供給している限り問題なく動作します。ただし、何か悪いこと ( などasdf()
) を入力すると、プログラムがクラッシュします。エラーを適切に処理しないのはなぜですか?
私は以前に通話を中断しようとしました。それ自体への呼び出しでクラッシュしlua_pcall
ます。私はその線を超えることはありません。