lua-users home
lua-l archive

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

> 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;