lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


This should do what you want when evaluated in the REPL:

setmetatable(_ENV, {__index = function(t, k) if k == '_PROMPT' then t._N = (t._N or 0) + 1; return t._N .. ' >' end end})

On Thu, Oct 22, 2020 at 4:35 AM Александр Машин <traditio.ru@gmail.com> wrote:
Dear all,

Why doesn't interactive Lua takes into account the __tostring metamethod
of the non-string _PROMPT global when it prints the prompt, so that the
below code does not help to increment the prompt on any typed command,
although on any >=_PROMPT the variable is incremented?

|>_PROMPT = {no = 0}; setmetatable (_PROMPT, {__tostring = function
(self) self.no = self.no + 1; return tostring (self.no) .. ' >' end})|

https://stackoverflow.com/a/64474830/6632736


Alexander Mashin