Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concat operator does only tries to invoke metamethod from lhs #494

Open
powercode opened this issue Jun 19, 2023 · 0 comments
Open

Concat operator does only tries to invoke metamethod from lhs #494

powercode opened this issue Jun 19, 2023 · 0 comments

Comments

@powercode
Copy link

powercode commented Jun 19, 2023

The metamethod is probed in p1 (LHS) and, if not found in p1, p2 (RHS) in the C implementation.

static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2,
                       StkId res, TMS event) {
  const TValue *tm = luaT_gettmbyobj(L, p1, event);  /* try first operand */
  if (ttisnil(tm))
    tm = luaT_gettmbyobj(L, p2, event);  /* try second operand */
  if (ttisnil(tm)) return 0;
  callTM(L, tm, p1, p2, res, 1);
  return 1;
}

This implementation does not try to find the metamethod in RHS:

internal static string RtConcatString(object[] args)
{
    if (Array.FindExists(args, a => a is LuaTable)) // do we have a table, then we use the metatable
        return RtConcatStringTable(args, 0);
    else
    {
        var strings = new string[args.Length];
        for (var i = 0; i < args.Length; i++)
            strings[i] = (string)RtConvertValue(args[i], typeof(string));
        return String.Concat(strings);
    }
} // func RtConcatString

This seems like a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant