Scripting: send print() to stdout if no console is installed

This commit is contained in:
Adam Higerd 2025-01-02 18:45:12 -06:00 committed by Vicki Pfau
parent 0ccd3c84dc
commit 419435c35b
1 changed files with 13 additions and 1 deletions

View File

@ -1573,7 +1573,19 @@ static int _luaRequireShim(lua_State* lua) {
static int _luaPrintShim(lua_State* lua) {
int n = lua_gettop(lua);
lua_getglobal(lua, "console");
if (lua_getglobal(lua, "console") == LUA_TNIL) {
// There is no console installed, so output to stdout
lua_pop(lua, 1);
for (int i = 1; i <= n; i++) {
const char* str = luaL_tolstring(lua, i, NULL);
if (i > 1) {
printf("\t");
}
printf("%s", str);
}
printf("\n");
return 0;
}
lua_insert(lua, 1);
// The first upvalue is either "log" or "warn"