luaL_typename() public static method

public static luaL_typename ( IntPtr luaState, int stackPos ) : string
luaState System.IntPtr
stackPos int
return string
Exemplo n.º 1
0
        private static int Print(IntPtr L)
        {
            try
            {
                int n  = LuaDLL.lua_gettop(L);
                var sb = new StringBuilder();

                //获得当前运行的函数的上一个调用层的信息,返回行数,把调用层的名称入栈
                int    line     = LuaDLL.jlua_where(L, 1);
                string filename = LuaDLL.lua_tostring(L, -1);

                LuaDLL.lua_settop(L, n);
                int offset = filename[0] == '@' ? 1 : 0;
                sb.Append('[').Append(filename, offset, filename.Length - offset).Append(':').Append(line).Append("]:");

                for (int i = 1; i <= n; i++)
                {
                    if (i > 1)
                    {
                        sb.Append("    ");
                    }

                    if (LuaDLL.lua_isstring(L, i) == 1)
                    {
                        sb.Append(LuaDLL.lua_tostring(L, i));
                    }
                    else if (LuaDLL.lua_isnil(L, i))
                    {
                        sb.Append("nil");
                    }
                    else if (LuaDLL.lua_isboolean(L, i))
                    {
                        sb.Append(LuaDLL.jlua_toboolean(L, i) ? "true" : "false");
                    }
                    else
                    {
                        IntPtr p = LuaDLL.lua_topointer(L, i);

                        if (p == IntPtr.Zero)
                        {
                            sb.Append("nil");
                        }
                        else
                        {
                            sb.Append(LuaDLL.luaL_typename(L, i)).Append(":0x").Append(p.ToString("X"));
                        }
                    }
                }
                Debug.Log(sb.ToString());
                return(0);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 2
0
        public static int luaL_typerror(IntPtr L, int stackPos, string tname, string t2 = null)
        {
            if (t2 == null)
            {
                t2 = LuaDLL.luaL_typename(L, stackPos);
            }
            string extramsg = string.Format("{1} expected, got {2}", stackPos - 1, tname, t2);

            return(LuaDLL.luaL_argerror(L, stackPos, extramsg));
        }
Exemplo n.º 3
0
        static int Print(IntPtr L)
        {
            try
            {
                int           n  = LuaDLL.lua_gettop(L);
                StringBuilder sb = new StringBuilder();//StringBuilderCache.Acquire();
                sb.Append(LuaWhere(L));

                for (int i = 1; i <= n; i++)
                {
                    if (i > 1)
                    {
                        sb.Append("    ");
                    }

                    if (LuaDLL.lua_isstring(L, i) == 1)
                    {
                        sb.Append(LuaDLL.lua_tostring(L, i));
                    }
                    else if (LuaDLL.lua_isnil(L, i))
                    {
                        sb.Append("nil");
                    }
                    else if (LuaDLL.lua_isboolean(L, i))
                    {
                        sb.Append(LuaDLL.lua_toboolean(L, i) ? "true" : "false");
                    }
                    else
                    {
                        IntPtr p = LuaDLL.lua_topointer(L, i);

                        if (p == IntPtr.Zero)
                        {
                            sb.Append("nil");
                        }
                        else
                        {
                            sb.AppendFormat("{0}:0x{1}", LuaDLL.luaL_typename(L, i), p.ToString("X"));
                        }
                    }
                }

                Debugger.Log(sb.ToString());
                return(0);
            }
            catch (Exception e)
            {
                return(LuaDLL.toluaL_exception(L, e));
            }
        }
Exemplo n.º 4
0
        private static int Print(IntPtr L)
        {
            int result;

            try
            {
                int           num           = LuaDLL.lua_gettop(L);
                StringBuilder stringBuilder = StringBuilderCache.Acquire(256);
                stringBuilder.Append(LuaStatic.LuaWhere(L));
                for (int i = 1; i <= num; i++)
                {
                    if (i > 1)
                    {
                        stringBuilder.Append("    ");
                    }
                    if (LuaDLL.lua_isstring(L, i) == 1)
                    {
                        stringBuilder.Append(LuaDLL.lua_tostring(L, i));
                    }
                    else if (LuaDLL.lua_isnil(L, i))
                    {
                        stringBuilder.Append("nil");
                    }
                    else if (LuaDLL.lua_isboolean(L, i))
                    {
                        stringBuilder.Append((!LuaDLL.lua_toboolean(L, i)) ? "false" : "true");
                    }
                    else
                    {
                        IntPtr intPtr = LuaDLL.lua_topointer(L, i);
                        if (intPtr == IntPtr.Zero)
                        {
                            stringBuilder.Append("nil");
                        }
                        else
                        {
                            stringBuilder.AppendFormat("{0}:0x{1}", LuaDLL.luaL_typename(L, i), intPtr.ToString("X"));
                        }
                    }
                }
                Debugger.Log(stringBuilder.ToString());
                result = 0;
            }
            catch (Exception e)
            {
                result = LuaDLL.toluaL_exception(L, e, null);
            }
            return(result);
        }
Exemplo n.º 5
0
        static int Print(IntPtr L)
        {
            try
            {
                int    n = LuaDLL.lua_gettop(L);
                string s = LuaWhere(L);

                for (int i = 1; i <= n; i++)
                {
                    if (i > 1)
                    {
                        s += "    ";
                    }

                    if (LuaDLL.lua_isstring(L, i) == 1)
                    {
                        s += LuaDLL.lua_tostring(L, i);
                    }
                    else if (LuaDLL.lua_isnil(L, i))
                    {
                        s += "nil";
                    }
                    else if (LuaDLL.lua_isboolean(L, i))
                    {
                        s += LuaDLL.lua_toboolean(L, i) ? "true" : "false";
                    }
                    else
                    {
                        IntPtr p = LuaDLL.lua_topointer(L, i);

                        if (p == IntPtr.Zero)
                        {
                            s += "nil";
                        }
                        else
                        {
                            s += string.Format("{0}:0x{1}", LuaDLL.luaL_typename(L, i), p.ToString("X"));
                        }
                    }
                }

                Debugger.Log(s);
                return(0);
            }
            catch (Exception e)
            {
                return(LuaDLL.toluaL_exception(L, e));
            }
        }
Exemplo n.º 6
0
        public static bool CheckType(IntPtr L, Type type, int pos)
        {
            Il2cppType il = il2cpp;

            //默认都可以转 object
            if (type == il.TypeOfObject)
            {
                return(true);
            }

            Type     t       = GetNullableType(type);
            LuaTypes luaType = LuaDLL.lua_type(L, pos);

            switch (luaType)
            {
            case LuaTypes.LUA_TNUMBER:
                return(IsNumberType(t));

            case LuaTypes.LUA_TSTRING:
                return(t == il.TypeOfString || t == il.TypeOfByteArray || t == il.TypeOfCharArray || t == il.TypeOfLuaByteBuffer);

            case LuaTypes.LUA_TUSERDATA:
                return(IsMatchUserData(L, t, pos));

            case LuaTypes.LUA_TBOOLEAN:
                return(t == il.TypeOfBool);

            case LuaTypes.LUA_TFUNCTION:
                return(t == il.TypeOfLuaFunction);

            case LuaTypes.LUA_TTABLE:
                return(IsUserTable(t, L, pos));

            case LuaTypes.LUA_TLIGHTUSERDATA:
                return(t == il.TypeOfIntPtr || t == il.TypeOfUIntPtr);

            case LuaTypes.LUA_TNIL:
                return(IsNilType(type));

            default:
                break;
            }

            throw new LuaException("undefined type to check" + LuaDLL.luaL_typename(L, pos));
        }
Exemplo n.º 7
0
        public static bool CheckType(IntPtr L, Type t, int pos)
        {
            //Debug.Log(" Type t  " + t.ToString());
            //默认都可以转 object
            if (t == typeof(object))
            {
                return(true);
            }

            t = GetNullableType(t);
            LuaTypes luaType = LuaDLL.lua_type(L, pos);

            //Debug.Log(" luaType  " + luaType.ToString() + " GetNullableType " +  t.ToString());
            switch (luaType)
            {
            case LuaTypes.LUA_TNUMBER:
                return(IsNumberType(t));

            case LuaTypes.LUA_TSTRING:
                return(t == typeof(string) || t == typeof(byte[]) || t == typeof(char[]));

            case LuaTypes.LUA_TUSERDATA:
                return(IsMatchUserData(L, t, pos));

            case LuaTypes.LUA_TBOOLEAN:
                return(t == typeof(bool));

            case LuaTypes.LUA_TFUNCTION:
                return(t == typeof(LuaFunction));

            case LuaTypes.LUA_TTABLE:
                return(IsUserTable(L, t, pos));

            case LuaTypes.LUA_TLIGHTUSERDATA:
                return(t == typeof(IntPtr) || t == typeof(UIntPtr));

            case LuaTypes.LUA_TNIL:
                return(IsNilType(t));

            default:
                break;
            }

            throw new LuaException("undefined type to check" + LuaDLL.luaL_typename(L, pos));
        }
Exemplo n.º 8
0
        public static bool CheckType(IntPtr L, Type t, int pos)
        {
            //默认都可以转 object
            if (t == typeof(object))
            {
                return(true);
            }

            LuaTypes luaType = LuaDLL.lua_type(L, pos);

            switch (luaType)
            {
            case LuaTypes.LUA_TNUMBER:
                return(t.IsPrimitive);

            case LuaTypes.LUA_TSTRING:
                return(t == typeof(string) || t == typeof(byte[]) || t == typeof(char[]));

            case LuaTypes.LUA_TUSERDATA:
                return(IsMatchUserData(L, t, pos));

            case LuaTypes.LUA_TBOOLEAN:
                return(t == typeof(bool));

            case LuaTypes.LUA_TFUNCTION:
                return(t == typeof(LuaFunction));                               //重载函数先不支持委托赋值函数

            case LuaTypes.LUA_TTABLE:
                return(lua_isusertable(L, t, pos));

            case LuaTypes.LUA_TLIGHTUSERDATA:
                return(t == typeof(IntPtr));

            case LuaTypes.LUA_TNIL:
                return(t == null || t.IsEnum || !t.IsValueType);

            default:
                LuaDLL.luaL_error(L, "undefined type to check" + LuaDLL.luaL_typename(L, pos));
                break;
            }

            return(false);
        }
Exemplo n.º 9
0
        public static bool CheckType(IntPtr L, Type t, int pos)
        {
            //默认都可以转 object
            if (t == typeof(object))
            {
                return(true);
            }
            LuaTypes luaType = LuaDLL.lua_type(L, pos);

            switch (luaType)
            {
            case LuaTypes.LUA_TNUMBER:
                return(t.IsPrimitive || t.IsEnum);

            case LuaTypes.LUA_TSTRING:
                return(t == typeof(string) || t == typeof(byte[]) || t == typeof(char[]) || t == typeof(Type));

            case LuaTypes.LUA_TUSERDATA:
                IntPtr ptr = LuaDLL.lua_touserdata(L, pos);
                return(t == typeof(object) || objs.ContainsKey(ptr.ToInt64()));

            case LuaTypes.LUA_TBOOLEAN:
                return(t == typeof(bool));

            case LuaTypes.LUA_TTABLE:
                return(lua_isusertable(L, t, pos));

            case LuaTypes.LUA_TFUNCTION:
                return(true);

            //return t == typeof(LuaFunction);
            case LuaTypes.LUA_TLIGHTUSERDATA:
                return(t == typeof(IntPtr));

            case LuaTypes.LUA_TNIL:
                return(t == null || t.IsEnum || !t.IsValueType);

            default:
                break;
            }
            traceback(L, "undefined type to check" + LuaDLL.luaL_typename(L, pos));
            return(false);
        }
Exemplo n.º 10
0
        public static object GetObj(IntPtr luaState, int index)
        {
            switch (LuaDLL.lua_type(luaState, index))
            {
            case LuaTypes.LUA_TNIL:
                return(null);

            case LuaTypes.LUA_TBOOLEAN:
                return(LuaDLL.lua_toboolean(luaState, index));

            case LuaTypes.LUA_TLIGHTUSERDATA:
                return(LuaDLL.lua_touserdata(luaState, index));

            case LuaTypes.LUA_TNUMBER:
                return(LuaDLL.lua_tonumber(luaState, index));

            case LuaTypes.LUA_TSTRING:
                return(LuaDLL.lua_tostring(luaState, index));

            case LuaTypes.LUA_TTABLE:
                return(ToStruct(luaState, index));

            case LuaTypes.LUA_TUSERDATA: {
                object obj2;
                IntPtr ptr = LuaDLL.lua_touserdata(luaState, index);
                if (!LuaStatic.objs.TryGetValue(ptr.ToInt64(), out obj2))
                {
                    traceback(luaState, "GetObj: obj not exist");
                    LuaDLL.lua_error(luaState);
                    return(null);
                }
                return(obj2);
            }
            }
            traceback(luaState, "GetObj: wrong value type: " + LuaDLL.luaL_typename(luaState, index));
            LuaDLL.lua_error(luaState);
            return(null);
        }
Exemplo n.º 11
0
        public static bool CheckType(IntPtr L, Type t, int pos)
        {
            if (t == typeof(object))
            {
                return(true);
            }
            t = TypeChecker.GetNullableType(t);
            switch (LuaDLL.lua_type(L, pos))
            {
            case LuaTypes.LUA_TNIL:
                return(TypeChecker.IsNilType(t));

            case LuaTypes.LUA_TBOOLEAN:
                return(t == typeof(bool));

            case LuaTypes.LUA_TLIGHTUSERDATA:
                return(t == typeof(IntPtr) || t == typeof(UIntPtr));

            case LuaTypes.LUA_TNUMBER:
                return(TypeChecker.IsNumberType(t));

            case LuaTypes.LUA_TSTRING:
                return(t == typeof(string) || t == typeof(byte[]) || t == typeof(char[]));

            case LuaTypes.LUA_TTABLE:
                return(TypeChecker.IsUserTable(L, t, pos));

            case LuaTypes.LUA_TFUNCTION:
                return(t == typeof(LuaFunction));

            case LuaTypes.LUA_TUSERDATA:
                return(TypeChecker.IsMatchUserData(L, t, pos));

            default:
                throw new LuaException("undefined type to check" + LuaDLL.luaL_typename(L, pos), null, 1);
            }
        }
Exemplo n.º 12
0
        public static bool CheckType(IntPtr L, Type t, int pos)
        {
            if (t == typeof(object))
            {
                return(true);
            }
            switch (LuaDLL.lua_type(L, pos))
            {
            case LuaTypes.LUA_TNIL:
                return(t == null || t.get_IsEnum() || !t.get_IsValueType());

            case LuaTypes.LUA_TBOOLEAN:
                return(t == typeof(bool));

            case LuaTypes.LUA_TLIGHTUSERDATA:
                return(t == typeof(IntPtr));

            case LuaTypes.LUA_TNUMBER:
                return(t.get_IsPrimitive());

            case LuaTypes.LUA_TSTRING:
                return(t == typeof(string) || t == typeof(byte[]) || t == typeof(char[]));

            case LuaTypes.LUA_TTABLE:
                return(TypeChecker.lua_isusertable(L, t, pos));

            case LuaTypes.LUA_TFUNCTION:
                return(t == typeof(LuaFunction));

            case LuaTypes.LUA_TUSERDATA:
                return(TypeChecker.IsMatchUserData(L, t, pos));

            default:
                throw new LuaException("undefined type to check" + LuaDLL.luaL_typename(L, pos), null, 1);
            }
        }
Exemplo n.º 13
0
 public string LuaTypeName(int idx)
 {
     return(LuaDLL.luaL_typename(L, idx));
 }
Exemplo n.º 14
0
        /// <summary>
        /// TODO:打印的简易版本,还需要lua的文件名位置等信息
        /// </summary>
        /// <param name="L"></param>
        public static int Print(IntPtr L)
        {
            try
            {
                int n = LuaDLL.lua_gettop(L);
                // CString可以喝String互转
                using (CString.Block())
                {
                    CString sb = CString.Alloc(256);
#if UNITY_EDITOR
                    int    line     = LuaDLL.tolua_where(L, 1);
                    string filename = LuaDLL.lua_tostring(L, -1);
                    LuaDLL.lua_settop(L, n);
                    int offset = filename[0] == '@' ? 1 : 0;

                    if (!filename.Contains("."))
                    {
                        sb.Append('[').Append(filename, offset, filename.Length - offset).Append(".lua:").Append(line).Append("]:");
                    }
                    else
                    {
                        sb.Append('[').Append(filename, offset, filename.Length - offset).Append(':').Append(line).Append("]:");
                    }
#endif

                    for (int i = 1; i <= n; i++)
                    {
                        if (i > 1)
                        {
                            sb.Append("    ");
                        }

                        if (LuaDLL.lua_isstring(L, i) == 1)
                        {
                            sb.Append(LuaDLL.lua_tostring(L, i));
                        }
                        else if (LuaDLL.lua_isnil(L, i))
                        {
                            sb.Append("nil");
                        }
                        else if (LuaDLL.lua_isboolean(L, i))
                        {
                            sb.Append(LuaDLL.lua_toboolean(L, i) ? "true" : "false");
                        }
                        else
                        {
                            IntPtr p = LuaDLL.lua_topointer(L, i);

                            if (p == IntPtr.Zero)
                            {
                                sb.Append("nil");
                            }
                            else
                            {
                                sb.Append(LuaDLL.luaL_typename(L, i)).Append(":0x").Append(p.ToString("X"));
                            }
                        }
                    }

                    Debugger.Log(sb.ToString());            //203行与_line一致
                }
                return(0);
            }
            catch (Exception e)
            {
                return(LuaDLL.toluaL_exception(L, e));
            }
        }
Exemplo n.º 15
0
        static int Print_Warning(IntPtr L)
        {
            try
            {
                int           n  = LuaDLL.lua_gettop(L);
                StringBuilder sb = StringBuilderCache.Acquire();
#if UNITY_EDITOR2
                int    line     = LuaDLL.tolua_where(L, 1);
                string filename = LuaDLL.lua_tostring(L, -1);
                LuaDLL.lua_settop(L, n);

                if (!filename.Contains("."))
                {
                    sb.AppendFormat("[{0}.lua:{1}]:", filename, line);
                }
                else
                {
                    sb.AppendFormat("[{0}:{1}]:", filename, line);
                }
#endif

                sb.Append("[");
                sb.Append(DateTime.Now.ToString("HH:mm:ss"));
                sb.Append("] ");

                for (int i = 1; i <= n; i++)
                {
                    if (i > 1)
                    {
                        sb.Append("    ");
                    }

                    if (LuaDLL.lua_isstring(L, i) == 1)
                    {
                        sb.Append(LuaDLL.lua_tostring(L, i));
                    }
                    else if (LuaDLL.lua_isnil(L, i))
                    {
                        sb.Append("nil");
                    }
                    else if (LuaDLL.lua_isboolean(L, i))
                    {
                        sb.Append(LuaDLL.lua_toboolean(L, i) ? "true" : "false");
                    }
                    else
                    {
                        IntPtr p = LuaDLL.lua_topointer(L, i);

                        if (p == IntPtr.Zero)
                        {
                            sb.Append("nil");
                        }
                        else
                        {
                            sb.AppendFormat("{0}:0x{1}", LuaDLL.luaL_typename(L, i), p.ToString("X"));
                        }
                    }
                }

                GameBase.Debugger.LogWarning_Fixed(StringBuilderCache.GetStringAndRelease(sb));
                return(0);
            }
            catch (Exception e)
            {
                return(LuaDLL.toluaL_exception(L, e));
            }
        }