예제 #1
0
        public static int Len(IntPtr ptr)
        {
            Array a = (Array)CheckSelf(ptr);

            LuaObject.PushValue(ptr, a.Length);
            return(1);
        }
예제 #2
0
 public static int LuaIndex(IntPtr ptr)
 {
     try
     {
         Array a = (Array)CheckSelf(ptr);
         if (LuaNativeMethods.lua_type(ptr, 2) == LuaTypes.TYPE_STRING)
         {
             string mn;
             CheckType(ptr, 2, out mn);
             ArrayPropFunction fun;
             if (propertyMethods.TryGetValue(mn, out fun))
             {
                 LuaObject.PushValue(ptr, true);
                 return(fun(ptr, a) + 1);
             }
             else
             {
                 throw new Exception("Can't find property named " + mn);
             }
         }
         else
         {
             int i;
             CheckType(ptr, 2, out i);
             LuaObject.Assert(i > 0, "index base 1");
             LuaObject.PushValue(ptr, true);
             LuaObject.PushVar(ptr, a.GetValue(i - 1));
             return(2);
         }
     }
     catch (Exception e)
     {
         return(Error(ptr, e));
     }
 }
예제 #3
0
        public static new int ToString(IntPtr ptr)
        {
            Array a = (Array)LuaObject.CheckSelf(ptr);

            LuaObject.PushValue(ptr, string.Format("Array<{0}>", a.GetType().GetElementType().Name));
            return(1);
        }
예제 #4
0
        public static int Constructor(IntPtr ptr)
        {
            try
            {
                int       argc = LuaNativeMethods.lua_gettop(ptr);
                ByteArray o;
                if (argc == 1)
                {
                    o = new ByteArray();
                    LuaObject.PushValue(ptr, true);
                    LuaObject.PushValue(ptr, o);
                    return(2);
                }
                else if (argc == 2)
                {
                    byte[] a1;
                    LuaObject.CheckArray(ptr, 2, out a1);
                    o = new ByteArray(a1);
                    LuaObject.PushValue(ptr, true);
                    LuaObject.PushValue(ptr, o);
                    return(2);
                }

                return(Error(ptr, "New object failed."));
            }
            catch (Exception e)
            {
                return(Error(ptr, e));
            }
        }
예제 #5
0
        public static new int ToString(IntPtr ptr)
        {
            try
            {
                object o = CheckObj(ptr, 1);
                if (o == null)
                {
                    LuaObject.PushValue(ptr, true);
                    LuaNativeMethods.lua_pushnil(ptr);
                    return(2);
                }

                LuaObject.PushValue(ptr, true);
                if (o is byte[])
                {
                    byte[] b = (byte[])o;
                    LuaNativeMethods.lua_pushlstring(ptr, b, b.Length);
                }
                else
                {
                    LuaObject.PushValue(ptr, o.ToString());
                }

                return(2);
            }
            catch (Exception e)
            {
                return(Error(ptr, e));
            }
        }
예제 #6
0
        public static int MakeArray(IntPtr ptr)
        {
            try
            {
                Type t;
                CheckType(ptr, 1, out t);
                LuaNativeMethods.luaL_checktype(ptr, 2, LuaTypes.TYPE_TABLE);
                int   n     = LuaNativeMethods.lua_rawlen(ptr, 2);
                Array array = Array.CreateInstance(t, n);
                for (int k = 0; k < n; k++)
                {
                    LuaNativeMethods.lua_rawgeti(ptr, 2, k + 1);
                    object obj = LuaObject.CheckVar(ptr, -1);
                    array.SetValue(LuaObject.ChangeType(obj, t), k);
                    LuaNativeMethods.lua_pop(ptr, 1);
                }

                LuaObject.PushValue(ptr, true);
                LuaObject.PushValue(ptr, array);
                return(2);
            }
            catch (Exception e)
            {
                return(Error(ptr, e));
            }
        }
예제 #7
0
 public static int GetPosition(IntPtr ptr)
 {
     try
     {
         ByteArray self = (ByteArray)LuaObject.CheckSelf(ptr);
         LuaObject.PushValue(ptr, true);
         LuaObject.PushValue(ptr, self.Position);
         return(2);
     }
     catch (Exception e)
     {
         return(Error(ptr, e));
     }
 }
예제 #8
0
 public static int Clear(IntPtr ptr)
 {
     try
     {
         ByteArray self = (ByteArray)LuaObject.CheckSelf(ptr);
         self.Clear();
         LuaObject.PushValue(ptr, true);
         return(1);
     }
     catch (Exception e)
     {
         return(Error(ptr, e));
     }
 }
예제 #9
0
 public static int ToBytes(IntPtr ptr)
 {
     try
     {
         byte[] bytes = null;
         LuaObject.CheckBinaryString(ptr, 1, out bytes);
         LuaObject.PushValue(ptr, true);
         LuaObject.PushObject(ptr, bytes);
         return(2);
     }
     catch (System.Exception e)
     {
         return(Error(ptr, e));
     }
 }
예제 #10
0
 public static int ReadBytes(IntPtr ptr)
 {
     try
     {
         ByteArray self = (ByteArray)LuaObject.CheckSelf(ptr);
         byte[]    ret  = self.ReadBytes();
         LuaObject.PushValue(ptr, true);
         LuaObject.PushValue(ptr, ret);
         return(2);
     }
     catch (Exception e)
     {
         return(Error(ptr, e));
     }
 }
예제 #11
0
 public static int ReadUInt64(IntPtr ptr)
 {
     try
     {
         ByteArray self = (ByteArray)LuaObject.CheckSelf(ptr);
         ulong     ret  = self.ReadUnsignedLongInt();
         LuaObject.PushValue(ptr, true);
         LuaObject.PushValue(ptr, ret);
         return(2);
     }
     catch (Exception e)
     {
         return(Error(ptr, e));
     }
 }
예제 #12
0
 public static int WriteBytes(IntPtr ptr)
 {
     try
     {
         ByteArray self = (ByteArray)LuaObject.CheckSelf(ptr);
         byte[]    a1;
         LuaObject.CheckArray(ptr, 2, out a1);
         self.WriteBytes(a1);
         LuaObject.PushValue(ptr, true);
         return(1);
     }
     catch (Exception e)
     {
         return(Error(ptr, e));
     }
 }
예제 #13
0
 public static int WriteInt48(IntPtr ptr)
 {
     try
     {
         ByteArray self = (ByteArray)LuaObject.CheckSelf(ptr);
         long      a1;
         CheckType(ptr, 2, out a1);
         self.WriteInt48(a1);
         LuaObject.PushValue(ptr, true);
         return(1);
     }
     catch (Exception e)
     {
         return(Error(ptr, e));
     }
 }
예제 #14
0
        public static int Iterator(IntPtr ptr)
        {
            object o = CheckObj(ptr, 1);

            if (o is IEnumerable)
            {
                IEnumerable e    = o as IEnumerable;
                IEnumerator iter = e.GetEnumerator();
                LuaObject.PushValue(ptr, true);
                LuaObject.PushLightObject(ptr, iter);
                LuaNativeMethods.lua_pushcclosure(ptr, _iter, 1);
                return(2);
            }

            return(Error(ptr, "passed in object isn't enumerable"));
        }
예제 #15
0
 public static int SetPosition(IntPtr ptr)
 {
     try
     {
         ByteArray self = (ByteArray)LuaObject.CheckSelf(ptr);
         int       v;
         CheckType(ptr, 2, out v);
         self.Position = v;
         LuaObject.PushValue(ptr, true);
         return(1);
     }
     catch (Exception e)
     {
         return(Error(ptr, e));
     }
 }
예제 #16
0
        public static int CreateClass(IntPtr ptr)
        {
            try
            {
                string cls;
                CheckType(ptr, 1, out cls);
                Type t = LuaObject.FindType(cls);
                if (t == null)
                {
                    return(Error(ptr, string.Format("Can't find {0} to create", cls)));
                }

                ConstructorInfo[] cis    = t.GetConstructors();
                ConstructorInfo   target = null;
                for (int n = 0; n < cis.Length; n++)
                {
                    ConstructorInfo ci = cis[n];
                    if (LuaObject.MatchType(ptr, LuaNativeMethods.lua_gettop(ptr), 2, ci.GetParameters()))
                    {
                        target = ci;
                        break;
                    }
                }

                if (target != null)
                {
                    ParameterInfo[] pis  = target.GetParameters();
                    object[]        args = new object[pis.Length];
                    for (int n = 0; n < pis.Length; n++)
                    {
                        args[n] = LuaObject.ChangeType(LuaObject.CheckVar(ptr, n + 2), pis[n].ParameterType);
                    }

                    object ret = target.Invoke(args);
                    LuaObject.PushValue(ptr, true);
                    LuaObject.PushVar(ptr, ret);
                    return(2);
                }

                LuaObject.PushValue(ptr, true);
                return(1);
            }
            catch (Exception e)
            {
                return(Error(ptr, e));
            }
        }
예제 #17
0
        public static int Import(IntPtr ptr)
        {
            try
            {
                LuaNativeMethods.luaL_checktype(ptr, 1, LuaTypes.TYPE_STRING);
                string str = LuaNativeMethods.lua_tostring(ptr, 1);

                string[] ns = str.Split('.');

                LuaNativeMethods.lua_pushglobaltable(ptr);

                for (int n = 0; n < ns.Length; n++)
                {
                    LuaNativeMethods.lua_getfield(ptr, -1, ns[n]);
                    if (!LuaNativeMethods.lua_istable(ptr, -1))
                    {
                        return(LuaObject.Error(ptr, "expect {0} is type table", ns));
                    }

                    LuaNativeMethods.lua_remove(ptr, -2);
                }

                LuaNativeMethods.lua_pushnil(ptr);
                while (LuaNativeMethods.lua_next(ptr, -2) != 0)
                {
                    string key = LuaNativeMethods.lua_tostring(ptr, -2);
                    LuaNativeMethods.lua_getglobal(ptr, key);
                    if (!LuaNativeMethods.lua_isnil(ptr, -1))
                    {
                        LuaNativeMethods.lua_pop(ptr, 1);
                        return(LuaObject.Error(ptr, "{0} had existed, import can't overload it.", key));
                    }

                    LuaNativeMethods.lua_pop(ptr, 1);
                    LuaNativeMethods.lua_setglobal(ptr, key);
                }

                LuaNativeMethods.lua_pop(ptr, 1);

                LuaObject.PushValue(ptr, true);
                return(1);
            }
            catch (Exception e)
            {
                return(LuaObject.Error(ptr, e));
            }
        }
예제 #18
0
 public static new void Init(IntPtr ptr)
 {
     propertyMethods["Table"]  = ToTable;
     propertyMethods["Length"] = Length;
     LuaNativeMethods.lua_createtable(ptr, 0, 5);
     LuaObject.PushValue(ptr, LuaIndex);
     LuaNativeMethods.lua_setfield(ptr, -2, "__index");
     LuaObject.PushValue(ptr, LuaNewIndex);
     LuaNativeMethods.lua_setfield(ptr, -2, "__newindex");
     LuaNativeMethods.lua_pushcfunction(ptr, LuaObject.LuaGC);
     LuaNativeMethods.lua_setfield(ptr, -2, "__gc");
     LuaNativeMethods.lua_pushcfunction(ptr, ToString);
     LuaNativeMethods.lua_setfield(ptr, -2, "__tostring");
     LuaNativeMethods.lua_pushcfunction(ptr, Len);
     LuaNativeMethods.lua_setfield(ptr, -2, "__len");
     LuaNativeMethods.lua_setfield(ptr, LuaIndexes.LUARegistryIndex, "LuaArray");
 }
예제 #19
0
 public static int Read(IntPtr ptr)
 {
     try
     {
         ByteArray self = (ByteArray)LuaObject.CheckSelf(ptr);
         byte[]    a1;
         CheckType(ptr, 2, out a1);
         self.Read(ref a1);
         LuaObject.PushValue(ptr, true);
         LuaObject.PushValue(ptr, a1);
         return(2);
     }
     catch (Exception e)
     {
         return(Error(ptr, e));
     }
 }
예제 #20
0
 public static int Find_s(IntPtr ptr)
 {
     UnityEngine.Debug.Log("GameObject.Find overloaded my MyGameObject.Find");
     try
     {
         string a1;
         CheckType(ptr, 1, out a1);
         GameObject ret = UnityEngine.GameObject.Find(a1);
         LuaObject.PushValue(ptr, true);
         LuaObject.PushValue(ptr, ret);
         return(2);
     }
     catch (Exception e)
     {
         return(Error(ptr, e));
     }
 }
예제 #21
0
        public static int CreateAction(IntPtr ptr)
        {
            try
            {
                LuaFunction func;
                CheckType(ptr, 1, out func);
                Action action = new Action(() =>
                {
                    func.Call();
                });

                LuaObject.PushValue(ptr, true);
                LuaObject.PushVar(ptr, action);
                return(2);
            }
            catch (Exception e)
            {
                return(Error(ptr, e));
            }
        }
예제 #22
0
        public static int As(IntPtr ptr)
        {
            try
            {
                if (!LuaObject.IsTypeTable(ptr, 2))
                {
                    return(Error(ptr, "No matched type of param 2"));
                }

                string meta = LuaNativeMethods.lua_tostring(ptr, -1);
                LuaNativeMethods.luaL_getmetatable(ptr, meta);
                LuaNativeMethods.lua_setmetatable(ptr, 1);
                LuaObject.PushValue(ptr, true);
                LuaNativeMethods.lua_pushvalue(ptr, 1);
                return(2);
            }
            catch (Exception e)
            {
                return(Error(ptr, e));
            }
        }
예제 #23
0
        public static int YieldValue(IntPtr ptr)
        {
            try
            {
                if (LuaNativeMethods.lua_pushthread(ptr) == 1)
                {
                    return(Error(ptr, "should put Yield call into lua coroutine."));
                }

                object      y = CheckObj(ptr, 1);
                LuaFunction f;
                CheckType(ptr, 2, out f);
                Behaviour.StartCoroutine(YieldReturn(y, f));
                LuaObject.PushValue(ptr, true);
                return(1);
            }
            catch (Exception e)
            {
                return(Error(ptr, e));
            }
        }
예제 #24
0
        public static int GetClass(IntPtr ptr)
        {
            try
            {
                string cls;
                CheckType(ptr, 1, out cls);
                Type t = LuaObject.FindType(cls);
                if (t == null)
                {
                    return(Error(ptr, "Can't find {0} to create", cls));
                }

                LuaClassObject co = new LuaClassObject(t);
                LuaObject.PushValue(ptr, true);
                LuaObject.PushObject(ptr, co);
                return(2);
            }
            catch (Exception e)
            {
                return(Error(ptr, e));
            }
        }
예제 #25
0
        public static int SetData(IntPtr ptr)
        {
            try
            {
                int argc = LuaNativeMethods.lua_gettop(ptr);
                if (argc == 2)
                {
                    ByteArray self = (ByteArray)LuaObject.CheckSelf(ptr);
                    byte[]    a1;
                    LuaObject.CheckArray(ptr, 2, out a1);
                    self.SetData(a1);
                    LuaObject.PushValue(ptr, true);
                    return(1);
                }
                else if (argc == 4)
                {
                    ByteArray self = (ByteArray)LuaObject.CheckSelf(ptr);
                    byte[]    a1;
                    LuaObject.CheckArray(ptr, 2, out a1);
                    int a2;
                    CheckType(ptr, 3, out a2);
                    int a3;
                    CheckType(ptr, 4, out a3);
                    self.SetData(a1, a2, a3);
                    LuaObject.PushValue(ptr, true);
                    return(1);
                }

                LuaObject.PushValue(ptr, false);
                LuaNativeMethods.lua_pushstring(ptr, "No matched override function SetData to call");
                return(2);
            }
            catch (Exception e)
            {
                return(Error(ptr, e));
            }
        }
예제 #26
0
        public static int IsNull(IntPtr ptr)
        {
            try
            {
                LuaTypes t = LuaNativeMethods.lua_type(ptr, 1);
                LuaObject.PushValue(ptr, true);

                if (t == LuaTypes.TYPE_NIL)
                {
                    LuaObject.PushValue(ptr, true);
                }
                else if (t == LuaTypes.TYPE_USERDATA || LuaObject.IsLuaClass(ptr, 1))
                {
                    // LUA_TUSERDATA or LUA_TTABLE(Class inherited from Unity Native)
                    object o = LuaObject.CheckObj(ptr, 1);
                    if (o is UnityEngine.Object)
                    {
                        LuaObject.PushValue(ptr, ((UnityEngine.Object)o) == null);
                    }
                    else
                    {
                        LuaObject.PushValue(ptr, o.Equals(null));
                    }
                }
                else
                {
                    LuaObject.PushValue(ptr, false);
                }

                return(2);
            }
            catch (Exception e)
            {
                return(Error(ptr, e));
            }
        }
예제 #27
0
        public static int DeleteAll(IntPtr ptr)
        {
            if (MapSnTimer == null)
            {
                return(0);
            }

            try
            {
                foreach (KeyValuePair <int, Timer> t in MapSnTimer)
                {
                    InnerDelete(t.Value, false);
                }

                MapSnTimer.Clear();

                LuaObject.PushValue(ptr, true);
                return(1);
            }
            catch (Exception e)
            {
                return(Error(ptr, e));
            }
        }
예제 #28
0
        public static int Loader(IntPtr ptr)
        {
            string fileName = LuaNativeMethods.lua_tostring(ptr, 1);

            byte[] bytes = LoadFile(fileName);
            if (bytes != null)
            {
                if (LuaNativeMethods.luaL_loadbuffer(ptr, bytes, bytes.Length, "@" + fileName) == 0)
                {
                    LuaObject.PushValue(ptr, true);
                    LuaNativeMethods.lua_insert(ptr, -2);
                    return(2);
                }
                else
                {
                    string errstr = LuaNativeMethods.lua_tostring(ptr, -1);
                    return(LuaObject.Error(ptr, errstr));
                }
            }

            LuaObject.PushValue(ptr, true);
            LuaNativeMethods.lua_pushnil(ptr);
            return(2);
        }
예제 #29
0
 public static void PushEnum(IntPtr ptr, int e)
 {
     LuaObject.PushValue(ptr, e);
 }
예제 #30
0
 public static int Length(IntPtr ptr, Array a)
 {
     LuaObject.PushValue(ptr, a.Length);
     return(1);
 }