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; }
public LuaValue New(LuaValue[] args) { if (Static) { throw new Exception("Cannot create an instance of a static class!"); } LuaClass n = ClassLib.CreateInstance(new LuaValue[] { this }) as LuaClass; n.Constructor.Invoke(args); return(n); }
public LuaValue IsParentOf(LuaValue[] args) { LuaClass _class = args[0] as LuaClass; foreach (LuaClass c in ChildClasses) { if (c.Name == _class.Name) { return(LuaBoolean.True); } } return(LuaBoolean.False); }
public LuaValue GetObject(LuaValue key, LuaClass p) { if ((p.Self.RawGetValue(key) != null) && (p.Self.RawGetValue(key) != LuaNil.Nil)) { return(p.Self.RawGetValue(key)); } else { foreach (LuaClass c in p.ParentClasses) { return(GetObject(key, c)); } } return(LuaNil.Nil); }
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; }
public LuaValue GetObject(LuaValue key, LuaClass p) { if ((p.Self.RawGetValue(key) != null) && (p.Self.RawGetValue(key) != LuaNil.Nil)) return p.Self.RawGetValue(key); else { foreach (LuaClass c in p.ParentClasses) return GetObject(key, c); } return LuaNil.Nil; }