Patrick Donnelly wrote:
Use debug.getinfo to see if your replacement print function is being
called from the first function on the call stack (the interpreter).
Luiz Henrique de Figueiredo wrote:
lua.c runs lines entered interactively using this:
status = luaL_loadbuffer(L, line, l, "=stdin");
So you can check whether the source is "=stdin":
print(debug.getinfo(1).source)
Thanks for these suggestions Patrick and Luiz! I'm thinking it may not
be optimal to call debug.getinfo() every time my redefined print()
function is called (because it may be called thousands of times even for
trivial scripts that call print() in a loop) but of course I can just
not redefine print() when debug.getinfo(1).source ~= '=stdin'.