Esempio n. 1
0
        static LuaObject EvalUnaryExpression(UnaryExpression Expression, LuaContext Context)
        {
            LuaObject obj = EvalExpression(Expression.Expression, Context)[0];

            switch (Expression.Operation)
            {
            case UnaryOp.Invert:
                return(-(obj.AsNumber()));

            case UnaryOp.Length:
            {
                if (obj.Is(LuaType.table))
                {
                    return(obj.AsTable().Count);
                }
                else
                {
                    return(obj.AsString().Length);
                }
            }

            case UnaryOp.Negate:
                return(!(obj.AsBool()));

            default:
                throw new NotImplementedException();
            }
        }
Esempio n. 2
0
        LuaArguments rawlen(LuaArguments args)
        {
            LuaObject obj = args[0];

            if (obj.IsString)
            {
                return(Return(obj.AsString().Length));
            }
            else if (obj.IsTable)
            {
                return(Return(obj.AsTable().Count));
            }
            else
            {
                throw new LuaException("invalid argument");
            }
        }
Esempio n. 3
0
 public static void rawset(LuaObject table, LuaObject key, LuaObject value)
 {
     if (table.IsTable)
     {
         var t = table.AsTable();
         if (t.ContainsKey(key))
         {
             t[key] = value;
         }
         else
         {
             t.Add(key, value);
         }
     }
     else
     {
         throw new LuaException("Invalid operation");
     }
 }
Esempio n. 4
0
        // This is all based on the Lua 5.2 manual
        // http://www.lua.org/manual/5.2/manual.html#2.4

        public static LuaObject rawget(LuaObject table, LuaObject index)
        {
            if (table.IsTable)
            {
                LuaObject obj;
                if (table.AsTable().TryGetValue(index, out obj))
                {
                    return(obj);
                }
                else
                {
                    return(LuaObject.Nil);
                }
            }
            else
            {
                throw new LuaException("Invalid operation");
            }
        }
Esempio n. 5
0
 internal static LuaObject len_event(LuaObject op)
 {
     if (op.IsString)
     {
         return(op.AsString().Length);
     }
     else
     {
         var handler = getMetamethod(op, "__len");
         if (!handler.IsNil)
         {
             return(handler.Call(op)[0]);
         }
         else if (op.IsTable)
         {
             return(op.AsTable().Count);
         }
         else
         {
             throw new LuaException("Invalid op");
         }
     }
 }