Exemple #1
0
        private static int SortComparer(ScriptExecutionContext executionContext, DynValue a, DynValue b, DynValue lt)
        {
            if (lt.IsNil())
            {
                lt = executionContext.GetBinaryMetamethod(a, b, "__lt");

                if (lt.IsNil())
                {
                    if (a.Type == DataType.Number && b.Type == DataType.Number)
                    {
                        return(a.Number.CompareTo(b.Number));
                    }
                    if (a.Type == DataType.String && b.Type == DataType.String)
                    {
                        return(a.String.CompareTo(b.String));
                    }

                    throw ScriptRuntimeException.CompareInvalidType(a, b);
                }
                else
                {
                    return(LuaComparerToClrComparer(
                               executionContext.GetScript().Call(lt, a, b),
                               executionContext.GetScript().Call(lt, b, a)));
                }
            }
            else
            {
                return(LuaComparerToClrComparer(
                           executionContext.GetScript().Call(lt, a, b),
                           executionContext.GetScript().Call(lt, b, a)));
            }
        }
        private int ExecLess(Instruction i, int instructionPtr)
        {
            DynValue r = m_ValueStack.Pop().ToScalar();
            DynValue l = m_ValueStack.Pop().ToScalar();

            if (l.Type == DataType.Number && r.Type == DataType.Number)
            {
                m_ValueStack.Push(DynValue.NewBoolean(l.Number < r.Number));
            }
            else if (l.Type == DataType.String && r.Type == DataType.String)
            {
                m_ValueStack.Push(DynValue.NewBoolean(l.String.CompareTo(r.String) < 0));
            }
            else
            {
                int ip = Internal_InvokeBinaryMetaMethod(l, r, "__lt", instructionPtr);
                if (ip < 0)
                {
                    throw ScriptRuntimeException.CompareInvalidType(l, r);
                }
                else
                {
                    return(ip);
                }
            }

            return(instructionPtr);
        }