Exemplo n.º 1
0
        public static LuaValue CreateClass(LuaValue[] args)
        {
            LuaTable from = new LuaTable();

            if (args.Length > 0)
            {
                if (args[0].GetTypeCode() == "table" && ((IsClass(new LuaValue[] { args[0] }) as LuaBoolean).BoolValue == false))
                {
                    from = args[0] as LuaTable;
                }
            }
            LuaClass        nClass  = new LuaClass("CLASS_" + classCount++, false, false);
            List <LuaClass> Parents = new List <LuaClass>();

            for (int i = 0; i < args.Length; i++)
            {
                LuaClass c = args[i] as LuaClass;
                if (c == null)
                {
                    continue;
                }
                if (c.Final)
                {
                    throw new Exception("Cannot inherit from a final class");
                }
                else
                {
                    Parents.Add(c);
                    c.ChildClasses.Add(nClass);
                }
            }
            nClass.ParentClasses = Parents;
            TableLib.Copy(new LuaValue[] { nClass.Self, from });
            return(nClass);
        }
Exemplo n.º 2
0
        public static LuaValue SetMetaTable(LuaValue[] values)
        {
            if ((values[0] as LuaClass) != null)
            {
                throw new Exception("Cannot set meta tables on Classes, use functions instead.");
            }
            LuaValue val = (LuaValue)values[0];

            if (val.MetaTable == null)
            {
                val.MetaTable = new LuaTable();
            }
            LuaTable metatable = (LuaTable)values[1];

            TableLib.Copy(new LuaValue[] { val.MetaTable, metatable });
            return(null);
        }
Exemplo n.º 3
0
        public static LuaValue CreateInstance(LuaValue[] args)
        {
            // copy args[0] to a new LuaClass and return it
            LuaClass c = args[0] as LuaClass;
            LuaClass n = new LuaClass(c.Name, c.Final, c.Static);

            n.CallFunction     = c.CallFunction;
            n.ChildClasses     = c.ChildClasses;
            n.IndexFunction    = c.IndexFunction;
            n.MetaTable        = c.MetaTable;
            n.NewIndexFunction = c.NewIndexFunction;
            n.ParentClasses    = c.ParentClasses;
            n.Constructor      = c.Constructor;
            n.Destructor       = c.Destructor;
            TableLib.Copy(new LuaValue[] { n.Self, c.Self });
            n.ToStringFunction = c.ToStringFunction;

            return(n);
        }