From 214734b627caa00305f7654dbeeef39cf8fcf6b6 Mon Sep 17 00:00:00 2001 From: jyelon Date: Mon, 25 Apr 2022 17:21:54 -0400 Subject: [PATCH] Add error-check for yield-in-pcall to traceback_pcall --- luprex/core/cpp/traceback.cpp | 5 ++++- luprex/core/cpp/traceback.hpp | 3 ++- luprex/core/cpp/world-core.cpp | 2 -- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/luprex/core/cpp/traceback.cpp b/luprex/core/cpp/traceback.cpp index 3f454acd..4842c04b 100644 --- a/luprex/core/cpp/traceback.cpp +++ b/luprex/core/cpp/traceback.cpp @@ -1,6 +1,7 @@ #include "traceback.hpp" #include +#include #define TRACEBACK_LEVELS1 12 #define TRACEBACK_LEVELS2 10 @@ -88,7 +89,9 @@ eng::string traceback_pcall(lua_State *L, int narg, int nret) { if ((msg == NULL) || (msg[0] == 0)) { msg = "unknown error"; } - return msg; + eng::string result = msg; + assert(result != "attempt to yield from outside a coroutine"); + return result; } return ""; } diff --git a/luprex/core/cpp/traceback.hpp b/luprex/core/cpp/traceback.hpp index fb6e6bbb..978b9a5b 100644 --- a/luprex/core/cpp/traceback.hpp +++ b/luprex/core/cpp/traceback.hpp @@ -25,7 +25,8 @@ int traceback_coroutine(lua_State *L); // Similar to lua_pcall, except that it automatically supplies // traceback_coroutine as a message handler. It also automatically // returns any error message. Returns empty string if there's -// no error. +// no error. Also checks for a yield inside a pcall, which is +// not allowed, and does an assert-fail in that case. // eng::string traceback_pcall(lua_State *L, int narg, int nret); diff --git a/luprex/core/cpp/world-core.cpp b/luprex/core/cpp/world-core.cpp index e53d206f..afb3d731 100644 --- a/luprex/core/cpp/world-core.cpp +++ b/luprex/core/cpp/world-core.cpp @@ -304,7 +304,6 @@ eng::string World::probe_lua(int64_t actor_id, const eng::string &lua) { (*ostream) << std::endl; } } else { - assert(msg != "attempt to yield from outside a coroutine"); (*ostream) << msg << std::endl; } @@ -366,7 +365,6 @@ void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) { Gui::store_global_pointer(L, nullptr); if (!msg.empty()) { gui->clear(0); - assert(msg != "attempt to yield from outside a coroutine"); std::cerr << msg << std::endl; LS.result(); return;