Example #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)));
            }
        }
Example #2
0
        private static int SortComparer(ScriptExecutionContext executionContext, DynValue a, DynValue b, DynValue lt)
        {
            if (lt == null || lt.IsNil())
            {
                lt = executionContext.GetBinaryMetamethod(a, b, "__lt");

                if (lt == null || 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);
                }
                return LuaComparerToClrComparer(
                    executionContext.GetScript().Call(lt, a, b),
                    executionContext.GetScript().Call(lt, b, a));
            }
            return LuaComparerToClrComparer(
                executionContext.GetScript().Call(lt, a, b),
                executionContext.GetScript().Call(lt, b, a));
        }