Esempio n. 1
0
 public bool Remove(LuaValue item)
 {
     return(this.list.Remove(item));
 }
Esempio n. 2
0
 public abstract LuaValue Evaluate(LuaValue baseValue, LuaTable enviroment);
Esempio n. 3
0
        public override LuaValue Evaluate(LuaValue baseValue, LuaTable enviroment)
        {
            LuaValue key = new LuaString(Name);

            return(LuaValue.GetKeyValue(baseValue, key));
        }
Esempio n. 4
0
        private LuaValue InfixBinaryOperation(Term LeftOperand, string Operator, Term RightOperand, LuaTable enviroment)
        {
            LuaValue leftValue  = LeftOperand.Evaluate(enviroment);
            LuaValue rightValue = RightOperand.Evaluate(enviroment);

            switch (Operator)
            {
            case "+":
                var left  = leftValue as LuaNumber;
                var right = rightValue as LuaNumber;
                if (left != null && right != null)
                {
                    return(new LuaNumber(left.Number + right.Number));
                }
                else
                {
                    LuaFunction func = GetMetaFunction("__add", leftValue, rightValue);
                    if (func != null)
                    {
                        return(func.Invoke(new LuaValue[] { leftValue, rightValue }));
                    }
                }
                break;

            case "-":
                left  = leftValue as LuaNumber;
                right = rightValue as LuaNumber;
                if (left != null && right != null)
                {
                    return(new LuaNumber(left.Number - right.Number));
                }
                else
                {
                    LuaFunction func = GetMetaFunction("__sub", leftValue, rightValue);
                    if (func != null)
                    {
                        return(func.Invoke(new LuaValue[] { leftValue, rightValue }));
                    }
                }
                break;

            case "*":
                left  = leftValue as LuaNumber;
                right = rightValue as LuaNumber;
                if (left != null && right != null)
                {
                    return(new LuaNumber(left.Number * right.Number));
                }
                else
                {
                    LuaFunction func = GetMetaFunction("__mul", leftValue, rightValue);
                    if (func != null)
                    {
                        return(func.Invoke(new LuaValue[] { leftValue, rightValue }));
                    }
                }
                break;

            case "/":
                left  = leftValue as LuaNumber;
                right = rightValue as LuaNumber;
                if (left != null && right != null)
                {
                    return(new LuaNumber(left.Number / right.Number));
                }
                else
                {
                    LuaFunction func = GetMetaFunction("__div", leftValue, rightValue);
                    if (func != null)
                    {
                        return(func.Invoke(new LuaValue[] { leftValue, rightValue }));
                    }
                }
                break;

            case "%":
                left  = leftValue as LuaNumber;
                right = rightValue as LuaNumber;
                if (left != null && right != null)
                {
                    return(new LuaNumber(left.Number % right.Number));
                }
                else
                {
                    LuaFunction func = GetMetaFunction("__mod", leftValue, rightValue);
                    if (func != null)
                    {
                        return(func.Invoke(new LuaValue[] { leftValue, rightValue }));
                    }
                }
                break;

            case "^":
                left  = leftValue as LuaNumber;
                right = rightValue as LuaNumber;
                if (left != null && right != null)
                {
                    return(new LuaNumber(Math.Pow(left.Number, right.Number)));
                }
                else
                {
                    LuaFunction func = GetMetaFunction("__pow", leftValue, rightValue);
                    if (func != null)
                    {
                        return(func.Invoke(new LuaValue[] { leftValue, rightValue }));
                    }
                }
                break;

            case "==":
                return(LuaBoolean.From(leftValue.Equals(rightValue)));

            case "~=":
                return(LuaBoolean.From(leftValue.Equals(rightValue) == false));

            case "<":
                int?compare = Compare(leftValue, rightValue);
                if (compare != null)
                {
                    return(LuaBoolean.From(compare < 0));
                }
                else
                {
                    LuaFunction func = GetMetaFunction("__lt", leftValue, rightValue);
                    if (func != null)
                    {
                        return(func.Invoke(new LuaValue[] { leftValue, rightValue }));
                    }
                }
                break;

            case ">":
                compare = Compare(leftValue, rightValue);
                if (compare != null)
                {
                    return(LuaBoolean.From(compare > 0));
                }
                else
                {
                    LuaFunction func = GetMetaFunction("__gt", leftValue, rightValue);
                    if (func != null)
                    {
                        return(func.Invoke(new LuaValue[] { leftValue, rightValue }));
                    }
                }
                break;

            case "<=":
                compare = Compare(leftValue, rightValue);
                if (compare != null)
                {
                    return(LuaBoolean.From(compare <= 0));
                }
                else
                {
                    LuaFunction func = GetMetaFunction("__le", leftValue, rightValue);
                    if (func != null)
                    {
                        return(func.Invoke(new LuaValue[] { leftValue, rightValue }));
                    }
                }
                break;

            case ">=":
                compare = Compare(leftValue, rightValue);
                if (compare != null)
                {
                    return(LuaBoolean.From(compare >= 0));
                }
                else
                {
                    LuaFunction func = GetMetaFunction("__ge", leftValue, rightValue);
                    if (func != null)
                    {
                        return(func.Invoke(new LuaValue[] { leftValue, rightValue }));
                    }
                }
                break;

            case "..":
                if ((leftValue is LuaString || leftValue is LuaNumber) &&
                    (rightValue is LuaString || rightValue is LuaNumber))
                {
                    return(new LuaString(string.Concat(leftValue, rightValue)));
                }
                else
                {
                    LuaFunction func = GetMetaFunction("__concat", leftValue, rightValue);
                    if (func != null)
                    {
                        return(func.Invoke(new LuaValue[] { leftValue, rightValue }));
                    }
                }
                break;

            case "and":
                bool leftBool  = leftValue.GetBooleanValue();
                bool rightBool = rightValue.GetBooleanValue();
                if (leftBool == false)
                {
                    return(leftValue);
                }
                else
                {
                    return(rightValue);
                }

            case "or":
                leftBool  = leftValue.GetBooleanValue();
                rightBool = rightValue.GetBooleanValue();
                if (leftBool == true)
                {
                    return(leftValue);
                }
                else
                {
                    return(rightValue);
                }
            }

            return(null);
        }
Esempio n. 5
0
        public override LuaValue Evaluate(LuaValue baseValue, LuaTable enviroment)
        {
            LuaValue key = Key.Evaluate(enviroment);

            return(LuaValue.GetKeyValue(baseValue, key));
        }