[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Take into account __tostring whet printing _PROMPT
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 22 Oct 2020 13:10:32 -0300
> Why doesn't interactive Lua takes into account the __tostring metamethod
> of the non-string _PROMPT global when it prints the prompt,
Replace get_prompt in lua.c by the code below and rebuild.
It seems to work, but it hasn't been thoroughly tested.
The original code uses lua_tostring, which does not honor the
__tostring metamethod; luaL_tolstring does.
static const char *get_prompt (lua_State *L, int firstline) {
const char *p;
if (lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2") == LUA_TNIL)
p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
else {
p = luaL_tolstring(L, -1, NULL);
lua_remove(L, -2); /* remove original value */
}
return p;
}