Example #1
0
        public int Call(RealStatePtr L)
        {
            try
            {
                if (overloads.Count == 1 && !overloads[0].HasDefalutValue) return overloads[0].Call(L);

                for (int i = 0; i < overloads.Count; ++i)
                {
                    var overload = overloads[i];
                    if (overload.Check(L))
                    {
                        return overload.Call(L);
                    }
                }
                return LuaAPI.luaL_error(L, "invalid arguments to " + methodName);
            }
            catch (System.Reflection.TargetInvocationException e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + e.InnerException.Message + ",stack:" + e.InnerException.StackTrace);
            }
            catch (System.Exception e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + e.Message + ",stack:" + e.StackTrace);
            }
        }
Example #2
0
        public static int ArrayIndexer(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                System.Array array = (System.Array)translator.FastGetCSObj(L, 1);

                if (array == null)
                {
                    return LuaAPI.luaL_error(L, "#1 parameter is not a array!");
                }

                int i = LuaAPI.xlua_tointeger(L, 2);

                if (i >= array.Length)
                {
                    return LuaAPI.luaL_error(L, "index out of range! i =" + i + ", array.Length=" + array.Length);
                }

                Type type = array.GetType();
                if (tryPrimitiveArrayGet(type, L, array, i))
                {
                    return 1;
                }

                if (genTryArrayGetPtr != null)
                {
                    try
                    {
                        if (genTryArrayGetPtr(type, L, translator, array, i))
                        {
                            return 1;
                        }
                    }
                    catch (Exception e)
                    {
                        return LuaAPI.luaL_error(L, "c# exception:" + e.Message + ",stack:" + e.StackTrace);
                    }
                }

                object ret = array.GetValue(i);
                translator.PushAny(L, ret);

                return 1;
            }
            catch (Exception e)
            {
                return LuaAPI.luaL_error(L, "c# exception in ArrayIndexer:" + e);
            }
        }
Example #3
0
        public ObjectTranslator Find(RealStatePtr L)
        {
            if (lastState == L) return lastTranslator;
            if (translators.ContainsKey(L))
            {
                lastState = L;
                lastTranslator = translators[L].Target as ObjectTranslator;
                return lastTranslator;
            }

            RealStatePtr main = Utils.GetMainState (L);

            if (translators.ContainsKey(main))
            {
                lastState = L;
                lastTranslator = translators[main].Target as ObjectTranslator;
                translators[L] = new WeakReference(lastTranslator);
                return lastTranslator;
            }

            return null;
        }
Example #4
0
        public static void BeginClassRegister(Type type, RealStatePtr L, LuaCSFunction creator, int class_field_count,
            int static_getter_count, int static_setter_count)
        {
            LuaAPI.lua_createtable(L, 0, class_field_count);

            int cls_table = LuaAPI.lua_gettop(L);

            SetCSTable(L, type, cls_table);

            LuaAPI.lua_createtable(L, 0, 3);
            int meta_table = LuaAPI.lua_gettop(L);
            if (creator != null)
            {
                LuaAPI.xlua_pushasciistring(L, "__call");
                LuaAPI.lua_pushstdcallcfunction(L, creator);
                LuaAPI.lua_rawset(L, -3);
            }

            if (static_getter_count == 0)
            {
                LuaAPI.lua_pushnil(L);
            }
            else
            {
                LuaAPI.lua_createtable(L, 0, static_getter_count);
            }

            if (static_setter_count == 0)
            {
                LuaAPI.lua_pushnil(L);
            }
            else
            {
                LuaAPI.lua_createtable(L, 0, static_setter_count);
            }
            LuaAPI.lua_pushvalue(L, meta_table);
            LuaAPI.lua_setmetatable(L, cls_table);
        }
Example #5
0
        public static int Compile(RealStatePtr L)
        {
            string snippet = LuaAPI.lua_tostring(L, 1);

            string code;
            try
            {
                code = ComposeCode(Parser.Parse(snippet));
            }
            catch (Exception e)
            {
                return LuaAPI.luaL_error(L, String.Format("template compile error:{0}\r\n", e.Message));
            }
            //UnityEngine.Debug.Log("code=" + code);
            if (LuaAPI.luaL_loadbuffer(L, code, "luatemplate") != 0)
            {
                return LuaAPI.lua_error(L);
            }
            return 1;
        }
Example #6
0
        public bool Check(RealStatePtr L)
        {
            int luaTop = LuaAPI.lua_gettop(L);
            int luaStackPos = luaStackPosStart;

            for(int i = 0; i < checkArray.Length; i++)
            {
                if ((i == (checkArray.Length - 1)) && (paramsType != null))
                {
                    break;
                }
                if(luaStackPos > luaTop && !isOptionalArray[i])
                {
                    return false;
                }
                else if(luaStackPos <= luaTop && !checkArray[i](L, luaStackPos))
                {
                    return false;
                }

                if (luaStackPos <= luaTop || !isOptionalArray[i])
                {
                    luaStackPos++;
                }
            }

            return paramsType != null ? (luaStackPos < luaTop + 1 ?
                checkArray[checkArray.Length - 1](L, luaStackPos) : true) : luaStackPos == luaTop + 1;
        }
Example #7
0
 static int FixCSFunction(RealStatePtr L)
 {
     try
     {
         ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
         int idx = LuaAPI.xlua_tointeger(L, LuaAPI.xlua_upvalueindex(1));
         LuaCSFunction func = (LuaCSFunction)translator.GetFixCSFunction(idx);
         return func(L);
     }
     catch (Exception e)
     {
         return LuaAPI.luaL_error(L, "c# exception in FixCSFunction:" + e);
     }
 }
Example #8
0
        internal static int LoadFromStreamingAssetsPath(RealStatePtr L)
        {
            try
            {
                string filename = LuaAPI.lua_tostring(L, 1).Replace('.', '/') + ".lua";
                var filepath = UnityEngine.Application.streamingAssetsPath + "/" + filename;
            #if UNITY_ANDROID && !UNITY_EDITOR
                UnityEngine.WWW www = new UnityEngine.WWW(filepath);
                while (true)
                {
                    if (www.isDone || !string.IsNullOrEmpty(www.error))
                    {
                        System.Threading.Thread.Sleep(50); //�Ƚ�hacker������
                        if (!string.IsNullOrEmpty(www.error))
                        {
                            LuaAPI.lua_pushstring(L, string.Format(
                               "\n\tno such file '{0}' in streamingAssetsPath!", filename));
                        }
                        else
                        {
                            UnityEngine.Debug.LogWarning("load lua file from StreamingAssets is obsolete, filename:" + filename);
                            if (LuaAPI.luaL_loadbuffer(L, www.text, "@" + filename) != 0)
                            {
                                return LuaAPI.luaL_error(L, String.Format("error loading module {0} from streamingAssetsPath, {1}",
                                    LuaAPI.lua_tostring(L, 1), LuaAPI.lua_tostring(L, -1)));
                            }
                        }
                        break;
                    }
                }
            #else
                if (File.Exists(filepath))
                {
                    Stream stream = File.Open(filepath, FileMode.Open, FileAccess.Read);
                    StreamReader reader = new StreamReader(stream);
                    string text = reader.ReadToEnd();
                    stream.Close();

                    UnityEngine.Debug.LogWarning("load lua file from StreamingAssets is obsolete, filename:" + filename);
                    if (LuaAPI.luaL_loadbuffer(L, text, "@" + filename) != 0)
                    {
                        return LuaAPI.luaL_error(L, String.Format("error loading module {0} from streamingAssetsPath, {1}",
                            LuaAPI.lua_tostring(L, 1), LuaAPI.lua_tostring(L, -1)));
                    }
                }
                else
                {
                    LuaAPI.lua_pushstring(L, string.Format(
                        "\n\tno such file '{0}' in streamingAssetsPath!", filename));
                }
            #endif
                return 1;
            }
            catch (System.Exception e)
            {
                return LuaAPI.luaL_error(L, "c# exception in LoadFromStreamingAssetsPath:" + e);
            }
        }
Example #9
0
        internal static int LoadBuiltinLib(RealStatePtr L)
        {
            try
            {
                string builtin_lib = LuaAPI.lua_tostring(L, 1);

                LuaEnv self = ObjectTranslatorPool.Instance.Find(L).luaEnv;

                LuaCSFunction initer;

                if (self.buildin_initer.TryGetValue(builtin_lib, out initer))
                {
                    LuaAPI.lua_pushstdcallcfunction(L, initer);
                }
                else
                {
                    LuaAPI.lua_pushstring(L, string.Format(
                        "\n\tno such builtin lib '{0}'", builtin_lib));
                }
                return 1;
            }
            catch (System.Exception e)
            {
                return LuaAPI.luaL_error(L, "c# exception in LoadBuiltinLib:" + e);
            }
        }
Example #10
0
 public static int ToString(RealStatePtr L)
 {
     try
     {
         ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
         object obj = translator.FastGetCSObj(L, 1);
         translator.PushAny(L, obj != null ? (obj.ToString() + ": " + obj.GetHashCode()) : "<invalid c# object>");
         return 1;
     }
     catch (Exception e)
     {
         return LuaAPI.luaL_error(L, "c# exception in ToString:" + e);
     }
 }
Example #11
0
 public static int ImportType(RealStatePtr L)
 {
     try
     {
         ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
         string className = LuaAPI.lua_tostring(L, 1);
         Type type = translator.FindType(className);
         if (type != null)
         {
             if (translator.TryDelayWrapLoader(L, type))
             {
                 LuaAPI.lua_pushboolean(L, true);
             }
             else
             {
                 return LuaAPI.luaL_error(L, "can not load type " + type);
             }
         }
         else
         {
             LuaAPI.lua_pushnil(L);
         }
         return 1;
     }
     catch (System.Exception e)
     {
         return LuaAPI.luaL_error(L, "c# exception in xlua.import_type:" + e);
     }
 }
Example #12
0
 private static object getDouble(RealStatePtr L, int idx, object target)
 {
     return(LuaAPI.lua_tonumber(L, idx));
 }
Example #13
0
 private static object ulongCaster(RealStatePtr L, int idx, object target)
 {
     return(LuaAPI.lua_touint64(L, idx));
 }
Example #14
0
 private static object uintCaster(RealStatePtr L, int idx, object target)
 {
     return(LuaAPI.xlua_touint(L, idx));
 }
Example #15
0
 private static object ushortCaster(RealStatePtr L, int idx, object target)
 {
     return((ushort)LuaAPI.xlua_tointeger(L, idx));
 }
Example #16
0
 private static object byteCaster(RealStatePtr L, int idx, object target)
 {
     return((byte)LuaAPI.xlua_tointeger(L, idx));
 }
Example #17
0
 private bool intptrCheck(RealStatePtr L, int idx)
 {
     return(LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TLIGHTUSERDATA);
 }
Example #18
0
        public static int Cast(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                Type type;
                translator.Get(L, 2, out type);

                if (type == null)
                {
                    return LuaAPI.luaL_error(L, "#2 param[" + LuaAPI.lua_tostring(L, 2) + "]is not valid type indicator");
                }
                LuaAPI.luaL_getmetatable(L, type.FullName);
                if (LuaAPI.lua_isnil(L, -1))
                {
                    return LuaAPI.luaL_error(L, "no gen code for " + LuaAPI.lua_tostring(L, 2));
                }
                LuaAPI.lua_setmetatable(L, 1);
                return 0;
            }
            catch (System.Exception e)
            {
                return LuaAPI.luaL_error(L, "c# exception in xlua.cast:" + e);
            }
        }
Example #19
0
 public static int DelegateCombine(RealStatePtr L)
 {
     try
     {
         var translator = ObjectTranslatorPool.Instance.Find(L);
         Type type = translator.FastGetCSObj(L, LuaAPI.lua_type(L, 1) == LuaTypes.LUA_TUSERDATA ? 1 : 2).GetType();
         Delegate d1 = translator.GetObject(L, 1, type) as Delegate;
         Delegate d2 = translator.GetObject(L, 2, type) as Delegate;
         if (d1 == null || d2 == null)
         {
             return LuaAPI.luaL_error(L, "one parameter must be a delegate, other one must be delegate or function");
         }
         translator.PushAny(L, Delegate.Combine(d1, d2));
         return 1;
     }
     catch (Exception e)
     {
         return LuaAPI.luaL_error(L, "c# exception in DelegateCombine:" + e);
     }
 }
Example #20
0
 private static object floatCaster(RealStatePtr L, int idx, object target)
 {
     return((float)LuaAPI.lua_tonumber(L, idx));
 }
Example #21
0
 public static int LuaGC(RealStatePtr L)
 {
     try
     {
         int udata = LuaAPI.xlua_tocsobj_safe(L, 1);
         if (udata != -1)
         {
             ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
             translator.collectObject(udata);
         }
         return 0;
     }
     catch (Exception e)
     {
         return LuaAPI.luaL_error(L, "c# exception in LuaGC:" + e);
     }
 }
Example #22
0
 private static object getBoolean(RealStatePtr L, int idx, object target)
 {
     return(LuaAPI.lua_toboolean(L, idx));
 }
Example #23
0
        public static int XLuaAccess(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                Type type = null;
                object obj = null;
                if (LuaAPI.lua_type(L, 1) == LuaTypes.LUA_TTABLE)
                {
                    LuaTable tbl;
                    translator.Get(L, 1, out tbl);
                    type = tbl.Get<Type>("UnderlyingSystemType");
                }
                else if (LuaAPI.lua_type(L, 1) == LuaTypes.LUA_TSTRING)
                {
                    string className = LuaAPI.lua_tostring(L, 1);
                    type = translator.FindType(className);
                }
                else if (LuaAPI.lua_type(L, 1) == LuaTypes.LUA_TUSERDATA)
                {
                    obj = translator.SafeGetCSObj(L, 1);
                    if (obj == null)
                    {
                        return LuaAPI.luaL_error(L, "xlua.access, #1 parameter must a type/c# object/string");
                    }
                    type = obj.GetType();
                }

                if (type == null)
                {
                    return LuaAPI.luaL_error(L, "xlua.access, can not find c# type");
                }

                string fieldName = LuaAPI.lua_tostring(L, 2);

                BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;

                if (LuaAPI.lua_gettop(L) > 2) // set
                {
                    var field = type.GetField(fieldName, bindingFlags);
                    if (field != null)
                    {
                        field.SetValue(obj, translator.GetObject(L, 3, field.FieldType));
                        return 0;
                    }
                    var prop = type.GetProperty(fieldName, bindingFlags);
                    if (prop != null)
                    {
                        prop.SetValue(obj, translator.GetObject(L, 3, prop.PropertyType), null);
                        return 0;
                    }
                }
                else
                {
                    var field = type.GetField(fieldName, bindingFlags);
                    if (field != null)
                    {
                        translator.PushAny(L, field.GetValue(obj));
                        return 1;
                    }
                    var prop = type.GetProperty(fieldName, bindingFlags);
                    if (prop != null)
                    {
                        translator.PushAny(L, prop.GetValue(obj, null));
                        return 1;
                    }
                }
                return LuaAPI.luaL_error(L, "xlua.access, no field " + fieldName);
            }
            catch(Exception e)
            {
                return LuaAPI.luaL_error(L, "c# exception in xlua.access: " + e);
            }
        }
Example #24
0
 private static object getString(RealStatePtr L, int idx, object target)
 {
     return(LuaAPI.lua_tostring(L, idx));
 }
Example #25
0
        internal static int LoadFromCustomLoaders(RealStatePtr L)
        {
            try
            {
                string filename = LuaAPI.lua_tostring(L, 1);

                LuaEnv self = ObjectTranslatorPool.Instance.Find(L).luaEnv;

                foreach (var loader in self.customLoaders)
                {
                    string real_file_path = filename;
                    byte[] bytes = loader(ref real_file_path);
                    if (bytes != null)
                    {
                        if (LuaAPI.xluaL_loadbuffer(L, bytes, bytes.Length, "@" + real_file_path) != 0)
                        {
                            return LuaAPI.luaL_error(L, String.Format("error loading module {0} from CustomLoader, {1}",
                                LuaAPI.lua_tostring(L, 1), LuaAPI.lua_tostring(L, -1)));
                        }
                        return 1;
                    }
                }
                LuaAPI.lua_pushstring(L, string.Format(
                    "\n\tno such file '{0}' in CustomLoaders!", filename));
                return 1;
            }
            catch (System.Exception e)
            {
                return LuaAPI.luaL_error(L, "c# exception in LoadFromCustomLoaders:" + e);
            }
        }
Example #26
0
 private object getBytes(RealStatePtr L, int idx, object target)
 {
     return(LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TSTRING ? LuaAPI.lua_tobytes(L, idx) : translator.SafeGetCSObj(L, idx) as byte[]);
 }
Example #27
0
 internal static int Panic(RealStatePtr L)
 {
     string reason = String.Format("unprotected error in call to Lua API ({0})", LuaAPI.lua_tostring(L, -1));
     throw new LuaException(reason);
 }
Example #28
0
 private object getIntptr(RealStatePtr L, int idx, object target)
 {
     return(LuaAPI.lua_touserdata(L, idx));
 }
Example #29
0
        static bool tryPrimitiveArrayGet(Type type, RealStatePtr L, object obj, int index)
        {
            bool ok = true;

            if (type == typeof(int[]))
            {
                int[] array = obj as int[];
                LuaAPI.xlua_pushinteger(L, array[index]);
            }
            else if (type == typeof(float[]))
            {
                float[] array = obj as float[];
                LuaAPI.lua_pushnumber(L, array[index]);
            }
            else if (type == typeof(double[]))
            {
                double[] array = obj as double[];
                LuaAPI.lua_pushnumber(L, array[index]);
            }
            else if (type == typeof(bool[]))
            {
                bool[] array = obj as bool[];
                LuaAPI.lua_pushboolean(L, array[index]);
            }
            else if (type == typeof(long[]))
            {
                long[] array = obj as long[];
                LuaAPI.lua_pushint64(L, array[index]);
            }
            else if (type == typeof(ulong[]))
            {
                ulong[] array = obj as ulong[];
                LuaAPI.lua_pushuint64(L, array[index]);
            }
            else if (type == typeof(sbyte[]))
            {
                sbyte[] array = obj as sbyte[];
                LuaAPI.xlua_pushinteger(L, array[index]);
            }
            else if (type == typeof(short[]))
            {
                short[] array = obj as short[];
                LuaAPI.xlua_pushinteger(L, array[index]);
            }
            else if (type == typeof(ushort[]))
            {
                ushort[] array = obj as ushort[];
                LuaAPI.xlua_pushinteger(L, array[index]);
            }
            else if (type == typeof(char[]))
            {
                char[] array = obj as char[];
                LuaAPI.xlua_pushinteger(L, array[index]);
            }
            else if (type == typeof(uint[]))
            {
                uint[] array = obj as uint[];
                LuaAPI.xlua_pushuint(L, array[index]);
            }
            else if (type == typeof(IntPtr[]))
            {
                IntPtr[] array = obj as IntPtr[];
                LuaAPI.lua_pushlightuserdata(L, array[index]);
            }
            else if (type == typeof(decimal[]))
            {
                decimal[] array = obj as decimal[];
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                translator.PushDecimal(L, array[index]);
            }
            else if (type == typeof(string[]))
            {
                string[] array = obj as string[];
                LuaAPI.lua_pushstring(L, array[index]);
            }
            else
            {
                ok = false;
            }
            return ok;
        }
Example #30
0
        private object getObject(RealStatePtr L, int idx, object target)
        {
            //return translator.getObject(L, idx); //TODO: translator.getObject move to here??
            LuaTypes type = (LuaTypes)LuaAPI.lua_type(L, idx);

            switch (type)
            {
            case LuaTypes.LUA_TNUMBER:
            {
                if (LuaAPI.lua_isint64(L, idx))
                {
                    return(LuaAPI.lua_toint64(L, idx));
                }
                else if (LuaAPI.lua_isinteger(L, idx))
                {
                    return(LuaAPI.xlua_tointeger(L, idx));
                }
                else
                {
                    return(LuaAPI.lua_tonumber(L, idx));
                }
            }

            case LuaTypes.LUA_TSTRING:
            {
                return(LuaAPI.lua_tostring(L, idx));
            }

            case LuaTypes.LUA_TBOOLEAN:
            {
                return(LuaAPI.lua_toboolean(L, idx));
            }

            case LuaTypes.LUA_TTABLE:
            {
                return(getLuaTable(L, idx, null));
            }

            case LuaTypes.LUA_TFUNCTION:
            {
                return(getLuaFunction(L, idx, null));
            }

            case LuaTypes.LUA_TUSERDATA:
            {
                if (LuaAPI.lua_isint64(L, idx))
                {
                    return(LuaAPI.lua_toint64(L, idx));
                }
                else if (LuaAPI.lua_isuint64(L, idx))
                {
                    return(LuaAPI.lua_touint64(L, idx));
                }
                else
                {
                    object obj = translator.SafeGetCSObj(L, idx);
                    return((obj is RawObject) ? (obj as RawObject).Target : obj);
                }
            }

            default:
                return(null);
            }
        }
        static int __CreateInstance(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                if (LuaAPI.lua_gettop(L) == 3 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3))
                {
                    float __time  = (float)LuaAPI.lua_tonumber(L, 2);
                    short __count = (short)LuaAPI.xlua_tointeger(L, 3);

                    var gen_ret = new UnityEngine.ParticleSystem.Burst(__time, __count);
                    translator.Push(L, gen_ret);

                    return(1);
                }
                if (LuaAPI.lua_gettop(L) == 4 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4))
                {
                    float __time     = (float)LuaAPI.lua_tonumber(L, 2);
                    short __minCount = (short)LuaAPI.xlua_tointeger(L, 3);
                    short __maxCount = (short)LuaAPI.xlua_tointeger(L, 4);

                    var gen_ret = new UnityEngine.ParticleSystem.Burst(__time, __minCount, __maxCount);
                    translator.Push(L, gen_ret);

                    return(1);
                }
                if (LuaAPI.lua_gettop(L) == 6 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 5) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 6))
                {
                    float __time           = (float)LuaAPI.lua_tonumber(L, 2);
                    short __minCount       = (short)LuaAPI.xlua_tointeger(L, 3);
                    short __maxCount       = (short)LuaAPI.xlua_tointeger(L, 4);
                    int   __cycleCount     = LuaAPI.xlua_tointeger(L, 5);
                    float __repeatInterval = (float)LuaAPI.lua_tonumber(L, 6);

                    var gen_ret = new UnityEngine.ParticleSystem.Burst(__time, __minCount, __maxCount, __cycleCount, __repeatInterval);
                    translator.Push(L, gen_ret);

                    return(1);
                }
                if (LuaAPI.lua_gettop(L) == 3 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) && translator.Assignable <UnityEngine.ParticleSystem.MinMaxCurve>(L, 3))
                {
                    float __time = (float)LuaAPI.lua_tonumber(L, 2);
                    UnityEngine.ParticleSystem.MinMaxCurve __count; translator.Get(L, 3, out __count);

                    var gen_ret = new UnityEngine.ParticleSystem.Burst(__time, __count);
                    translator.Push(L, gen_ret);

                    return(1);
                }
                if (LuaAPI.lua_gettop(L) == 5 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) && translator.Assignable <UnityEngine.ParticleSystem.MinMaxCurve>(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 5))
                {
                    float __time = (float)LuaAPI.lua_tonumber(L, 2);
                    UnityEngine.ParticleSystem.MinMaxCurve __count; translator.Get(L, 3, out __count);
                    int   __cycleCount     = LuaAPI.xlua_tointeger(L, 4);
                    float __repeatInterval = (float)LuaAPI.lua_tonumber(L, 5);

                    var gen_ret = new UnityEngine.ParticleSystem.Burst(__time, __count, __cycleCount, __repeatInterval);
                    translator.Push(L, gen_ret);

                    return(1);
                }

                if (LuaAPI.lua_gettop(L) == 1)
                {
                    translator.Push(L, default(UnityEngine.ParticleSystem.Burst));
                    return(1);
                }
            }
            catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.ParticleSystem.Burst constructor!"));
        }
Example #32
0
 private static bool objectCheck(RealStatePtr L, int idx)
 {
     return(true);
 }
Example #33
0
 public static int ArrayLength(RealStatePtr L)
 {
     try
     {
         ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
         System.Array array = (System.Array)translator.FastGetCSObj(L, 1);
         LuaAPI.xlua_pushinteger(L, array.Length);
         return 1;
     }
     catch (System.Exception e)
     {
         return LuaAPI.luaL_error(L, "c# exception in ArrayLength:" + e);
     }
 }
Example #34
0
 private bool luaTableCheck(RealStatePtr L, int idx)
 {
     return(LuaAPI.lua_isnil(L, idx) || LuaAPI.lua_istable(L, idx) || (LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TUSERDATA && translator.SafeGetCSObj(L, idx) is LuaTable));
 }
Example #35
0
 public static int DelegateCall(RealStatePtr L)
 {
     try
     {
         ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
         object objDelegate = translator.FastGetCSObj(L, 1);
         if (objDelegate == null || !(objDelegate is Delegate))
         {
             return LuaAPI.luaL_error(L, "trying to invoke a value that is not delegate nor callable");
         }
         return translator.methodWrapsCache.GetDelegateWrap(objDelegate.GetType())(L);
     }
     catch (Exception e)
     {
         return LuaAPI.luaL_error(L, "c# exception in DelegateCall:" + e);
     }
 }
Example #36
0
 private bool numberCheck(RealStatePtr L, int idx)
 {
     return(LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TNUMBER);
 }
Example #37
0
 public static int DelegateRemove(RealStatePtr L)
 {
     try
     {
         var translator = ObjectTranslatorPool.Instance.Find(L);
         Delegate d1 = translator.FastGetCSObj(L, 1) as Delegate;
         if (d1 == null)
         {
             return LuaAPI.luaL_error(L, "#1 parameter must be a delegate");
         }
         Delegate d2 = translator.GetObject(L, 2, d1.GetType()) as Delegate;
         if (d2 == null)
         {
             return LuaAPI.luaL_error(L, "#2 parameter must be a delegate or a function ");
         }
         translator.PushAny(L, Delegate.Remove(d1, d2));
         return 1;
     }
     catch (Exception e)
     {
         return LuaAPI.luaL_error(L, "c# exception in DelegateRemove:" + e);
     }
 }
Example #38
0
 private bool decimalCheck(RealStatePtr L, int idx)
 {
     return(LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TNUMBER || translator.IsDecimal(L, idx));
 }
Example #39
0
        public static int LoadAssembly(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                string assemblyName = LuaAPI.lua_tostring(L, 1);

                Assembly assembly = null;

                try
                {
                    assembly = Assembly.Load(assemblyName);
                }
                catch (BadImageFormatException)
                {
                    // The assemblyName was invalid.  It is most likely a path.
                }

                if (assembly == null)
                {
                    assembly = Assembly.Load(AssemblyName.GetAssemblyName(assemblyName));
                }

                if (assembly != null && !translator.assemblies.Contains(assembly))
                {
                    translator.assemblies.Add(assembly);
                }
                return 0;
            }
            catch (System.Exception e)
            {
                return LuaAPI.luaL_error(L, "c# exception in xlua.load_assembly:" + e);
            }
        }
Example #40
0
 private bool strCheck(RealStatePtr L, int idx)
 {
     return(LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TSTRING || LuaAPI.lua_isnil(L, idx));
 }
Example #41
0
 public static int MetaFuncIndex(RealStatePtr L)
 {
     try
     {
         ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
         Type type = translator.FastGetCSObj(L, 2) as Type;
         if (type == null)
         {
             return LuaAPI.luaL_error(L, "#2 param need a System.Type!");
         }
         //UnityEngine.Debug.Log("============================load type by __index:" + type);
         translator.TryDelayWrapLoader(L, type);
         LuaAPI.lua_pushvalue(L, 2);
         LuaAPI.lua_rawget(L, 1);
         return 1;
     }
     catch (System.Exception e)
     {
         return LuaAPI.luaL_error(L, "c# exception in MetaFuncIndex:" + e);
     }
 }
Example #42
0
 private bool bytesCheck(RealStatePtr L, int idx)
 {
     return(LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TSTRING || LuaAPI.lua_isnil(L, idx) || (LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TUSERDATA && translator.SafeGetCSObj(L, idx) is byte[]));
 }
Example #43
0
        public static bool TryPrimitiveArraySet(Type type, RealStatePtr L, object obj, int array_idx, int obj_idx)
        {
            bool ok = true;

            LuaTypes lua_type = LuaAPI.lua_type(L, obj_idx);

            if (type == typeof(int[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                int[] array = obj as int[];
                array[array_idx] = LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(float[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                float[] array = obj as float[];
                array[array_idx] = (float)LuaAPI.lua_tonumber(L, obj_idx);
            }
            else if (type == typeof(double[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                double[] array = obj as double[];
                array[array_idx] = LuaAPI.lua_tonumber(L, obj_idx); ;
            }
            else if (type == typeof(bool[]) && lua_type == LuaTypes.LUA_TBOOLEAN)
            {
                bool[] array = obj as bool[];
                array[array_idx] = LuaAPI.lua_toboolean(L, obj_idx);
            }
            else if (type == typeof(long[]) && LuaAPI.lua_isint64(L, obj_idx))
            {
                long[] array = obj as long[];
                array[array_idx] = LuaAPI.lua_toint64(L, obj_idx);
            }
            else if (type == typeof(ulong[]) && LuaAPI.lua_isuint64(L, obj_idx))
            {
                ulong[] array = obj as ulong[];
                array[array_idx] = LuaAPI.lua_touint64(L, obj_idx);
            }
            else if (type == typeof(sbyte[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                sbyte[] array = obj as sbyte[];
                array[array_idx] = (sbyte)LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(short[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                short[] array = obj as short[];
                array[array_idx] = (short)LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(ushort[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                ushort[] array = obj as ushort[];
                array[array_idx] = (ushort)LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(char[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                char[] array = obj as char[];
                array[array_idx] = (char)LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(uint[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                uint[] array = obj as uint[];
                array[array_idx] = LuaAPI.xlua_touint(L, obj_idx);
            }
            else if (type == typeof(IntPtr[]) && lua_type == LuaTypes.LUA_TLIGHTUSERDATA)
            {
                IntPtr[] array = obj as IntPtr[];
                array[array_idx] = LuaAPI.lua_touserdata(L, obj_idx);
            }
            else if (type == typeof(decimal[]))
            {
                decimal[] array = obj as decimal[];
                if (lua_type == LuaTypes.LUA_TNUMBER)
                {
                    array[array_idx] = (decimal)LuaAPI.lua_tonumber(L, obj_idx);
                }

                if (lua_type == LuaTypes.LUA_TUSERDATA)
                {
                    ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                    if (translator.IsDecimal(L, obj_idx))
                    {
                        translator.Get(L, obj_idx, out array[array_idx]);
                    }
                    else
                    {
                        ok = false;
                    }
                }
                else
                {
                    ok = false;
                }
            }
            else if (type == typeof(string[]) && lua_type == LuaTypes.LUA_TSTRING)
            {
                string[] array = obj as string[];
                array[array_idx] = LuaAPI.lua_tostring(L, obj_idx);
            }
            else
            {
                ok = false;
            }
            return ok;
        }
Example #44
0
 private bool boolCheck(RealStatePtr L, int idx)
 {
     return(LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TBOOLEAN);
 }
Example #45
0
        public static int XLuaPrivateAccessible(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                Type type = null;
                if (LuaAPI.lua_type(L, 1) == LuaTypes.LUA_TTABLE)
                {
                    LuaTable tbl;
                    translator.Get(L, 1, out tbl);
                    type = tbl.Get<Type>("UnderlyingSystemType");
                }
                else if (LuaAPI.lua_type(L, 1) == LuaTypes.LUA_TSTRING)
                {
                    string className = LuaAPI.lua_tostring(L, 1);
                    type = translator.FindType(className);
                }
                else
                {
                    return LuaAPI.luaL_error(L, "xlua.private_accessible, #1 parameter must a type/string");
                }

                if (type == null)
                {
                    return LuaAPI.luaL_error(L, "xlua.private_accessible, can not find c# type");
                }

                Utils.MakePrivateAccessible(L, type);
                return 0;
            }
            catch (Exception e)
            {
                return LuaAPI.luaL_error(L, "c# exception in xlua.private_accessible: " + e);
            }
        }
Example #46
0
 private bool uint64Check(RealStatePtr L, int idx)
 {
     return(LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TNUMBER || LuaAPI.lua_isuint64(L, idx));
 }
Example #47
0
 static int __CreateInstance(RealStatePtr L)
 {
     return(LuaAPI.luaL_error(L, "FairyGUI.IEventDispatcher does not have a constructor!"));
 }
Example #48
0
        public int Call(RealStatePtr L)
        {
            try
            {
#if UNITY_EDITOR && !DISABLE_OBSOLETE_WARNING
                if (method.IsDefined(typeof(ObsoleteAttribute), true))
                {
                    ObsoleteAttribute info = Attribute.GetCustomAttribute(method, typeof(ObsoleteAttribute)) as ObsoleteAttribute;
                    UnityEngine.Debug.LogWarning("Obsolete Method [" + method.DeclaringType.ToString() + "." + method.Name + "]: " + info.Message);
                }
#endif
                object     target   = null;
                MethodBase toInvoke = method;

                if (luaStackPosStart > 1)
                {
                    target = translator.FastGetCSObj(L, 1);
                    if (target is Delegate)
                    {
                        Delegate delegateInvoke = (Delegate)target;
#if UNITY_WSA && !UNITY_EDITOR
                        toInvoke = delegateInvoke.GetMethodInfo();
#else
                        toInvoke = delegateInvoke.Method;
#endif
                    }
                }


                int luaTop      = LuaAPI.lua_gettop(L);
                int luaStackPos = luaStackPosStart;

                for (int i = 0; i < castArray.Length; i++)
                {
                    //UnityEngine.Debug.Log("inPos:" + inPosArray[i]);
                    if (luaStackPos > luaTop) //after check
                    {
                        if (paramsType != null && i == castArray.Length - 1)
                        {
                            args[inPosArray[i]] = Array.CreateInstance(paramsType, 0);
                        }
                        else
                        {
                            args[inPosArray[i]] = defaultValueArray[i];
                        }
                    }
                    else
                    {
                        if (paramsType != null && i == castArray.Length - 1)
                        {
                            args[inPosArray[i]] = translator.GetParams(L, luaStackPos, paramsType);
                        }
                        else
                        {
                            args[inPosArray[i]] = castArray[i](L, luaStackPos, null);
                        }
                        luaStackPos++;
                    }
                    //UnityEngine.Debug.Log("value:" + args[inPosArray[i]]);
                }

                object ret = null;


                ret = toInvoke.IsConstructor ? ((ConstructorInfo)method).Invoke(args) : method.Invoke(targetNeeded ? target : null, args);

                int nRet = 0;

                if (!isVoid)
                {
                    //UnityEngine.Debug.Log(toInvoke.ToString() + " ret:" + ret);
                    translator.PushAny(L, ret);
                    nRet++;
                }

                for (int i = 0; i < outPosArray.Length; i++)
                {
                    if (refPos[outPosArray[i]] != -1)
                    {
                        translator.Update(L, luaStackPosStart + refPos[outPosArray[i]], args[outPosArray[i]]);
                    }
                    translator.PushAny(L, args[outPosArray[i]]);
                    nRet++;
                }

                return(nRet);
            }
            finally
            {
                for (int i = 0; i < args.Length; i++)
                {
                    args[i] = null;
                }
            }
        }
Example #49
0
        internal static int LoadFromResource(RealStatePtr L)
        {
            try
            {
                string filename = LuaAPI.lua_tostring(L, 1).Replace('.', '/') + ".lua";

                // Load with Unity3D resources
                UnityEngine.TextAsset file = (UnityEngine.TextAsset)UnityEngine.Resources.Load(filename);
                if (file == null)
                {
                    LuaAPI.lua_pushstring(L, string.Format(
                        "\n\tno such resource '{0}'", filename));
                }
                else
                {
                    if (LuaAPI.luaL_loadbuffer(L, file.text, "@" + filename) != 0)
                    {
                        return LuaAPI.luaL_error(L, String.Format("error loading module {0} from resource, {1}",
                            LuaAPI.lua_tostring(L, 1), LuaAPI.lua_tostring(L, -1)));
                    }
                }

                return 1;
            }
            catch (System.Exception e)
            {
                return LuaAPI.luaL_error(L, "c# exception in LoadFromResource:" + e);
            }
        }
Example #50
0
 static int __CreateInstance(RealStatePtr L)
 {
     return(LuaAPI.luaL_error(L, "JW.Common.ExtObject does not have a constructor!"));
 }
Example #51
0
 internal static int LoadSocketCore(RealStatePtr L)
 {
     return LuaAPI.luaopen_socket_core(L);
 }
        public static void __Register(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

            Utils.BeginObjectRegister(typeof(UnityEngine.Renderer), L, translator, 0, 3, 24, 19);

            Utils.RegisterFunc(L, Utils.METHOD_IDX, "SetPropertyBlock", _m_SetPropertyBlock);
            Utils.RegisterFunc(L, Utils.METHOD_IDX, "GetPropertyBlock", _m_GetPropertyBlock);
            Utils.RegisterFunc(L, Utils.METHOD_IDX, "GetClosestReflectionProbes", _m_GetClosestReflectionProbes);


            Utils.RegisterFunc(L, Utils.GETTER_IDX, "isPartOfStaticBatch", _g_get_isPartOfStaticBatch);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "worldToLocalMatrix", _g_get_worldToLocalMatrix);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "localToWorldMatrix", _g_get_localToWorldMatrix);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "enabled", _g_get_enabled);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "shadowCastingMode", _g_get_shadowCastingMode);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "receiveShadows", _g_get_receiveShadows);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "material", _g_get_material);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "sharedMaterial", _g_get_sharedMaterial);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "materials", _g_get_materials);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "sharedMaterials", _g_get_sharedMaterials);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "bounds", _g_get_bounds);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "lightmapIndex", _g_get_lightmapIndex);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "realtimeLightmapIndex", _g_get_realtimeLightmapIndex);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "lightmapScaleOffset", _g_get_lightmapScaleOffset);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "motionVectorGenerationMode", _g_get_motionVectorGenerationMode);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "realtimeLightmapScaleOffset", _g_get_realtimeLightmapScaleOffset);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "isVisible", _g_get_isVisible);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "lightProbeUsage", _g_get_lightProbeUsage);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "lightProbeProxyVolumeOverride", _g_get_lightProbeProxyVolumeOverride);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "probeAnchor", _g_get_probeAnchor);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "reflectionProbeUsage", _g_get_reflectionProbeUsage);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "sortingLayerName", _g_get_sortingLayerName);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "sortingLayerID", _g_get_sortingLayerID);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "sortingOrder", _g_get_sortingOrder);

            Utils.RegisterFunc(L, Utils.SETTER_IDX, "enabled", _s_set_enabled);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "shadowCastingMode", _s_set_shadowCastingMode);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "receiveShadows", _s_set_receiveShadows);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "material", _s_set_material);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "sharedMaterial", _s_set_sharedMaterial);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "materials", _s_set_materials);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "sharedMaterials", _s_set_sharedMaterials);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "lightmapIndex", _s_set_lightmapIndex);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "realtimeLightmapIndex", _s_set_realtimeLightmapIndex);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "lightmapScaleOffset", _s_set_lightmapScaleOffset);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "motionVectorGenerationMode", _s_set_motionVectorGenerationMode);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "realtimeLightmapScaleOffset", _s_set_realtimeLightmapScaleOffset);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "lightProbeUsage", _s_set_lightProbeUsage);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "lightProbeProxyVolumeOverride", _s_set_lightProbeProxyVolumeOverride);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "probeAnchor", _s_set_probeAnchor);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "reflectionProbeUsage", _s_set_reflectionProbeUsage);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "sortingLayerName", _s_set_sortingLayerName);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "sortingLayerID", _s_set_sortingLayerID);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "sortingOrder", _s_set_sortingOrder);

            Utils.EndObjectRegister(typeof(UnityEngine.Renderer), L, translator, null, null,
                                    null, null, null);

            Utils.BeginClassRegister(typeof(UnityEngine.Renderer), L, __CreateInstance, 1, 0, 0);



            Utils.RegisterObject(L, translator, Utils.CLS_IDX, "UnderlyingSystemType", typeof(UnityEngine.Renderer));


            Utils.EndClassRegister(typeof(UnityEngine.Renderer), L, translator);
        }
Example #53
0
        internal static int Print(RealStatePtr L)
        {
            try
            {
                int n = LuaAPI.lua_gettop(L);
                string s = String.Empty;

                if (0 != LuaAPI.xlua_getglobal(L, "tostring"))
                {
                    return LuaAPI.luaL_error(L, "can not get tostring in print:");
                }

                for (int i = 1; i <= n; i++)
                {
                    LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                    LuaAPI.lua_pushvalue(L, i);   /* value to print */
                    if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                    {
                        return LuaAPI.lua_error(L);
                    }
                    s += LuaAPI.lua_tostring(L, -1);

                    if (i != n) s += "\t";

                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
                UnityEngine.Debug.Log("LUA: " + s);
                return 0;
            }
            catch (System.Exception e)
            {
                return LuaAPI.luaL_error(L, "c# exception in print:" + e);
            }
        }
Example #54
0
        static bool tryPrimitiveArrayGet(Type type, RealStatePtr L, object obj, int index)
        {
            bool ok = true;

            if (type == typeof(int[]))
            {
                int[] array = obj as int[];
                LuaAPI.xlua_pushinteger(L, array[index]);
            }
            else if (type == typeof(float[]))
            {
                float[] array = obj as float[];
                LuaAPI.lua_pushnumber(L, array[index]);
            }
            else if (type == typeof(double[]))
            {
                double[] array = obj as double[];
                LuaAPI.lua_pushnumber(L, array[index]);
            }
            else if (type == typeof(bool[]))
            {
                bool[] array = obj as bool[];
                LuaAPI.lua_pushboolean(L, array[index]);
            }
            else if (type == typeof(long[]))
            {
                long[] array = obj as long[];
                LuaAPI.lua_pushint64(L, array[index]);
            }
            else if (type == typeof(ulong[]))
            {
                ulong[] array = obj as ulong[];
                LuaAPI.lua_pushuint64(L, array[index]);
            }
            else if (type == typeof(sbyte[]))
            {
                sbyte[] array = obj as sbyte[];
                LuaAPI.xlua_pushinteger(L, array[index]);
            }
            else if (type == typeof(short[]))
            {
                short[] array = obj as short[];
                LuaAPI.xlua_pushinteger(L, array[index]);
            }
            else if (type == typeof(ushort[]))
            {
                ushort[] array = obj as ushort[];
                LuaAPI.xlua_pushinteger(L, array[index]);
            }
            else if (type == typeof(char[]))
            {
                char[] array = obj as char[];
                LuaAPI.xlua_pushinteger(L, array[index]);
            }
            else if (type == typeof(uint[]))
            {
                uint[] array = obj as uint[];
                LuaAPI.xlua_pushuint(L, array[index]);
            }
            else if (type == typeof(IntPtr[]))
            {
                IntPtr[] array = obj as IntPtr[];
                LuaAPI.lua_pushlightuserdata(L, array[index]);
            }
            else if (type == typeof(decimal[]))
            {
                decimal[]        array      = obj as decimal[];
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                translator.PushDecimal(L, array[index]);
            }
            else if (type == typeof(string[]))
            {
                string[] array = obj as string[];
                LuaAPI.lua_pushstring(L, array[index]);
            }
            else
            {
                ok = false;
            }
            return(ok);
        }
Example #55
0
 static int StaticCSFunction(RealStatePtr L)
 {
     try
     {
         ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
         LuaCSFunction func = (LuaCSFunction)translator.FastGetCSObj(L, LuaAPI.xlua_upvalueindex(1));
         return func(L);
     }
     catch(Exception e)
     {
         return LuaAPI.luaL_error(L, "c# exception in StaticCSFunction:" + e);
     }
 }
 static int __CreateInstance(RealStatePtr L)
 {
     return(LuaAPI.luaL_error(L, "DCET.Model.IDeserializeSystem does not have a constructor!"));
 }
Example #57
0
        public int Call(RealStatePtr L)
        {
            object target = null;
            MethodBase toInvoke = method;

            if (luaStackPosStart > 1)
            {
                target = translator.FastGetCSObj(L, 1);
                if (target is Delegate)
                {
                    Delegate delegateInvoke = (Delegate)target;
                    toInvoke = delegateInvoke.Method;
                }
            }

            int luaTop = LuaAPI.lua_gettop(L);
            int luaStackPos = luaStackPosStart;

            for (int i = 0; i < castArray.Length; i++)
            {
                //UnityEngine.Debug.Log("inPos:" + inPosArray[i]);
                if (luaStackPos > luaTop) //after check
                {
                    args[inPosArray[i]] = defaultValueArray[i];
                }
                else
                {
                    if (paramsType != null && i == castArray.Length - 1)
                    {
                        args[inPosArray[i]] = translator.GetParams(L, luaStackPos, paramsType);
                    }
                    else
                    {
                        args[inPosArray[i]] = castArray[i](L, luaStackPos, null);
                    }
                    luaStackPos++;
                }
                //UnityEngine.Debug.Log("value:" + args[inPosArray[i]]);
            }

            object ret = null;

            ret = toInvoke.IsConstructor ? ((ConstructorInfo)method).Invoke(args) : method.Invoke(targetNeeded ? target : null, args);

            int nRet = 0;

            if (!isVoid)
            {
                //UnityEngine.Debug.Log(toInvoke.ToString() + " ret:" + ret);
                translator.PushAny(L, ret);
                nRet++;
            }

            for (int i = 0; i < outPosArray.Length; i++)
            {
                if (refPos[outPosArray[i]] != -1)
                {
                    translator.Update(L, luaStackPosStart + refPos[outPosArray[i]], args[outPosArray[i]]);
                }
                translator.PushAny(L, args[outPosArray[i]]);
                nRet++;
            }

            return nRet;
        }
Example #58
0
        internal static int Panic(RealStatePtr L)
        {
            string reason = String.Format("unprotected error in call to Lua API ({0})", LuaAPI.lua_tostring(L, -1));

            throw new LuaException(reason);
        }
Example #59
0
        public static bool TryPrimitiveArraySet(Type type, RealStatePtr L, object obj, int array_idx, int obj_idx)
        {
            bool ok = true;

            LuaTypes lua_type = LuaAPI.lua_type(L, obj_idx);

            if (type == typeof(int[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                int[] array = obj as int[];
                array[array_idx] = LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(float[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                float[] array = obj as float[];
                array[array_idx] = (float)LuaAPI.lua_tonumber(L, obj_idx);
            }
            else if (type == typeof(double[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                double[] array = obj as double[];
                array[array_idx] = LuaAPI.lua_tonumber(L, obj_idx);;
            }
            else if (type == typeof(bool[]) && lua_type == LuaTypes.LUA_TBOOLEAN)
            {
                bool[] array = obj as bool[];
                array[array_idx] = LuaAPI.lua_toboolean(L, obj_idx);
            }
            else if (type == typeof(long[]) && LuaAPI.lua_isint64(L, obj_idx))
            {
                long[] array = obj as long[];
                array[array_idx] = LuaAPI.lua_toint64(L, obj_idx);
            }
            else if (type == typeof(ulong[]) && LuaAPI.lua_isuint64(L, obj_idx))
            {
                ulong[] array = obj as ulong[];
                array[array_idx] = LuaAPI.lua_touint64(L, obj_idx);
            }
            else if (type == typeof(sbyte[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                sbyte[] array = obj as sbyte[];
                array[array_idx] = (sbyte)LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(short[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                short[] array = obj as short[];
                array[array_idx] = (short)LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(ushort[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                ushort[] array = obj as ushort[];
                array[array_idx] = (ushort)LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(char[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                char[] array = obj as char[];
                array[array_idx] = (char)LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(uint[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                uint[] array = obj as uint[];
                array[array_idx] = LuaAPI.xlua_touint(L, obj_idx);
            }
            else if (type == typeof(IntPtr[]) && lua_type == LuaTypes.LUA_TLIGHTUSERDATA)
            {
                IntPtr[] array = obj as IntPtr[];
                array[array_idx] = LuaAPI.lua_touserdata(L, obj_idx);
            }
            else if (type == typeof(decimal[]))
            {
                decimal[] array = obj as decimal[];
                if (lua_type == LuaTypes.LUA_TNUMBER)
                {
                    array[array_idx] = (decimal)LuaAPI.lua_tonumber(L, obj_idx);
                }

                if (lua_type == LuaTypes.LUA_TUSERDATA)
                {
                    ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                    if (translator.IsDecimal(L, obj_idx))
                    {
                        translator.Get(L, obj_idx, out array[array_idx]);
                    }
                    else
                    {
                        ok = false;
                    }
                }
                else
                {
                    ok = false;
                }
            }
            else if (type == typeof(string[]) && lua_type == LuaTypes.LUA_TSTRING)
            {
                string[] array = obj as string[];
                array[array_idx] = LuaAPI.lua_tostring(L, obj_idx);
            }
            else
            {
                ok = false;
            }
            return(ok);
        }
Example #60
0
 static int __CreateInstance(RealStatePtr L)
 {
     return(LuaAPI.luaL_error(L, "DCET.Model.JsonHelper does not have a constructor!"));
 }