3

I'm going for absolute minimalism here. (It's been a while since I've worked with the 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;
}

This program works fine as long as I feed it perfect Lua. However, if I enter something bad (such as asdf()), the program crashes! Why is it not handling my error gracefully?

I've tried breaking out the calls before. It crashes on the call to lua_pcall itself. I never make it past that line.

4

1 回答 1

1

二进制下载(我相信是 5.2.1)有一个在 5.2.3 中更正的错误。我从源代码重建了库,现在我的程序运行良好。

于 2014-03-27T19:13:40.947 回答