Implement C++ pretty-printer

This commit is contained in:
2021-09-08 01:32:08 -04:00
parent 67b309a0b7
commit bac1a7b876
9 changed files with 322 additions and 454 deletions

View File

@@ -14,6 +14,7 @@
#include "traceback.hpp"
#include "textgame.hpp"
#include "luaconsole.hpp"
#include "print.hpp"
// Add another error status.
@@ -54,17 +55,8 @@ void TextGame::do_lua(const std::string &exp) {
signal(SIGINT, SIG_DFL);
if (status == LUA_OK) {
if (lua_gettop(L) > 0) {
lua_getglobal(L, "pprint");
if (lua_isnil(L, -1)) {
lua_pop(L, 1);
lua_getglobal(L, "print");
}
lua_insert(L, 1);
if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0) {
l_message(
lua_pushfstring(L, "error calling 'print' (%s)",
lua_tostring(L, -1)));
}
lfn_pprint_pprint(L);
lua_settop(L, 0);
}
} else {
const char *msg = lua_tostring(L, -1);