コード例 #1
0
        internal int DoTraceback(LuaState state)
        {
            // if err is not a string, just pass it on (the stack is local to the function)
            // I spent a solid hour of debugging non stop only to fix the issue with this one line
            // (the issue was that nlua would throw exception objects and this thing would inappropriately
            // stringify them btw, if you're interested)
            if (!LuaLib.LuaIsString(state, -1))
            {
                return(LuaLib.LuaGetTop(state));
            }

            var error = LuaLib.LuaToString(state, -1);

            LuaLib.LuaPop(state, 1);

            LuaLib.LuaNewTable(state); // t

            LuaLib.LuaPushString(state, "__etgmod_error");
            LuaLib.LuaPushBoolean(state, true);
            LuaLib.LuaSetTable(state, -3);

            LuaLib.LuaPushString(state, "msg");          // k
            LuaLib.LuaPushString(state, error);          // v
            LuaLib.LuaSetTable(state, -3);               // t[k] = v

            LuaLib.LuaPushString(state, "traceback");    // k
            LuaLib.LuaLTraceback(state, state, null, 0); // v
            LuaLib.LuaSetTable(state, -3);               // t[k] = v

            return(1);                                   // t is left
        }
コード例 #2
0
ファイル: CheckType.cs プロジェクト: aron1982/Unity3D-NLua
        private object GetAsString(LuaState luaState, int stackPos)
        {
            if (!LuaLib.LuaIsString(luaState, stackPos))
            {
                return(null);
            }
            string retVal = LuaLib.LuaToString(luaState, stackPos).ToString();

            return(retVal);
        }
コード例 #3
0
        private object GetAsString(LuaState luaState, int stackPos)
        {
            string retVal = LuaLib.LuaToString(luaState, stackPos).ToString();

            if (string.IsNullOrEmpty(retVal) && !LuaLib.LuaIsString(luaState, stackPos))
            {
                return(null);
            }

            return(retVal);
        }
コード例 #4
0
        internal ExtractValue CheckLuaType(LuaState luaState, int stackPos, Type paramType)
        {
            var luatype = LuaLib.LuaType(luaState, stackPos);

            if (paramType.IsByRef)
            {
                paramType = paramType.GetElementType();
            }

            var underlyingType = Nullable.GetUnderlyingType(paramType);

            if (underlyingType != null)
            {
                paramType = underlyingType;                      // Silently convert nullable types to their non null requics
            }
            var extractKey = GetExtractDictionaryKey(paramType);

            if (paramType.Equals(typeof(object)))
            {
                return(extractValues [extractKey]);
            }

            //CP: Added support for generic parameters
            if (paramType.IsGenericParameter)
            {
                if (luatype == LuaTypes.Boolean)
                {
                    return(extractValues [GetExtractDictionaryKey(typeof(bool))]);
                }
                else if (luatype == LuaTypes.String)
                {
                    return(extractValues[GetExtractDictionaryKey(typeof(string))]);
                }
                else if (luatype == LuaTypes.Table)
                {
                    return(extractValues [GetExtractDictionaryKey(typeof(LuaTable))]);
                }
                else if (luatype == LuaTypes.UserData)
                {
                    return(extractValues [GetExtractDictionaryKey(typeof(object))]);
                }
                else if (luatype == LuaTypes.Function)
                {
                    return(extractValues [GetExtractDictionaryKey(typeof(LuaFunction))]);
                }
                else if (luatype == LuaTypes.Number)
                {
                    return(extractValues [GetExtractDictionaryKey(typeof(double))]);
                }
            }

            if (LuaLib.LuaIsNumber(luaState, stackPos))
            {
                return(extractValues [extractKey]);
            }

            if (paramType == typeof(bool))
            {
                if (LuaLib.LuaIsBoolean(luaState, stackPos))
                {
                    return(extractValues [extractKey]);
                }
            }
            else if (paramType == typeof(string) || paramType == typeof(char []))
            {
                if (LuaLib.LuaIsString(luaState, stackPos))
                {
                    return(extractValues [extractKey]);
                }
                else if (luatype == LuaTypes.Nil)
                {
                    return(extractNetObject);                    // kevinh - silently convert nil to a null string pointer
                }
            }
            else if (paramType == typeof(LuaTable))
            {
                if (luatype == LuaTypes.Table)
                {
                    return(extractValues [extractKey]);
                }
            }
            else if (paramType == typeof(LuaUserData))
            {
                if (luatype == LuaTypes.UserData)
                {
                    return(extractValues [extractKey]);
                }
            }
            else if (paramType == typeof(LuaFunction))
            {
                if (luatype == LuaTypes.Function)
                {
                    return(extractValues [extractKey]);
                }
            }
            else if (typeof(Delegate).IsAssignableFrom(paramType) && luatype == LuaTypes.Function)
            {
                return(new ExtractValue(new DelegateGenerator(translator, paramType).ExtractGenerated));
            }
            else if (paramType.IsInterface && luatype == LuaTypes.Table)
            {
                return(new ExtractValue(new ClassGenerator(translator, paramType).ExtractGenerated));
            }
            else if ((paramType.IsInterface || paramType.IsClass) && luatype == LuaTypes.Nil)
            {
                // kevinh - allow nil to be silently converted to null - extractNetObject will return null when the item ain't found
                return(extractNetObject);
            }
            else if (LuaLib.LuaType(luaState, stackPos) == LuaTypes.Table)
            {
                if (LuaLib.LuaLGetMetafield(luaState, stackPos, "__index"))
                {
                    object obj = translator.GetNetObject(luaState, -1);
                    LuaLib.LuaSetTop(luaState, -2);
                    if (obj != null && paramType.IsAssignableFrom(obj.GetType()))
                    {
                        return(extractNetObject);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                object obj = translator.GetNetObject(luaState, stackPos);
                if (obj != null && paramType.IsAssignableFrom(obj.GetType()))
                {
                    return(extractNetObject);
                }
            }

            return(null);
        }