Ejemplo n.º 1
0
        /// <summary>
        /// Create lookup from a Lua variable
        /// </summary>
        /// <param name="luaVar"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static SledLuaVarLookUpType FromLuaVar(ISledLuaVarBaseType luaVar, SledLuaVarLookUpContextType context)
        {
            try
            {
                var lookUp =
                    new DomNode(SledLuaSchema.SledLuaVarLookUpType.Type)
                    .As <SledLuaVarLookUpType>();

                lookUp.Scope   = luaVar.Scope;
                lookUp.Context = context;

                // Go through and generate a list of key/value pairs of the hierarchy so we can
                // look up and find the variable on the target no matter where it may be
                foreach (var nameAndType in luaVar.TargetHierarchy)
                {
                    lookUp.NamesAndTypes.Add((SledLuaVarNameTypePairType)nameAndType.Clone());
                }

                lookUp.NamesAndTypes.Add(SledLuaVarNameTypePairType.Create(luaVar.DisplayName, luaVar.KeyType));

                var index      = 0;
                var stackLevel = 0;

                // Some special processing if a local or upvalue variable
                if (luaVar.DomNode.Is <SledLuaVarLocalUpvalueBaseType>())
                {
                    var varTmp = luaVar.DomNode.As <SledLuaVarLocalUpvalueBaseType>();

                    stackLevel = varTmp.Level;
                    index      = varTmp.Index;
                }

                // Some special processing if an environment variable
                if (luaVar.DomNode.Is <SledLuaVarEnvType>())
                {
                    var varTmp = luaVar.DomNode.As <SledLuaVarEnvType>();

                    stackLevel = varTmp.Level;
                }

                lookUp.StackLevel = stackLevel;
                lookUp.Index      = index;

                return(lookUp);
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLineDebug(
                    SledMessageType.Error,
                    "{0}: Exception in FromLuaVar: {1}",
                    typeof(SledLuaVarLookUpType), ex.Message);

                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create lookup from a Lua variable
        /// </summary>
        /// <param name="luaVar"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static SledLuaVarLookUpType FromLuaVar(ISledLuaVarBaseType luaVar, SledLuaVarLookUpContextType context)
        {
            try
            {
                var lookUp =
                    new DomNode(SledLuaSchema.SledLuaVarLookUpType.Type)
                    .As<SledLuaVarLookUpType>();

                lookUp.Scope = luaVar.Scope;
                lookUp.Context = context;

                // Go through and generate a list of key/value pairs of the hierarchy so we can
                // look up and find the variable on the target no matter where it may be
                foreach (var nameAndType in luaVar.TargetHierarchy)
                    lookUp.NamesAndTypes.Add((SledLuaVarNameTypePairType)nameAndType.Clone());

                lookUp.NamesAndTypes.Add(SledLuaVarNameTypePairType.Create(luaVar.DisplayName, luaVar.KeyType));

                var index = 0;
                var stackLevel = 0;

                // Some special processing if a local or upvalue variable
                if (luaVar.DomNode.Is<SledLuaVarLocalUpvalueBaseType>())
                {
                    var varTmp = luaVar.DomNode.As<SledLuaVarLocalUpvalueBaseType>();

                    stackLevel = varTmp.Level;
                    index = varTmp.Index;
                }

                // Some special processing if an environment variable
                if (luaVar.DomNode.Is<SledLuaVarEnvType>())
                {
                    var varTmp = luaVar.DomNode.As<SledLuaVarEnvType>();

                    stackLevel = varTmp.Level;
                }

                lookUp.StackLevel = stackLevel;
                lookUp.Index = index;

                return lookUp;
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLineDebug(
                    SledMessageType.Error,
                    "{0}: Exception in FromLuaVar: {1}",
                    typeof(SledLuaVarLookUpType), ex.Message);

                return null;
            }
        }
Ejemplo n.º 3
0
        public static SledLuaVarLookUpType FromCustomValues(SledLuaVarScopeType scope, SledLuaVarLookUpContextType context, IList<SledLuaVarNameTypePairType> namesAndTypes)
        {
            try
            {
                var lookUp =
                    new DomNode(SledLuaSchema.SledLuaVarLookUpType.Type)
                    .As<SledLuaVarLookUpType>();

                lookUp.Scope = scope;
                lookUp.Context = context;

                foreach (var nameAndType in namesAndTypes)
                    lookUp.NamesAndTypes.Add((SledLuaVarNameTypePairType)nameAndType.Clone());

                lookUp.Index = 0;
                lookUp.StackLevel = 0;

                return lookUp;
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLineDebug(
                    SledMessageType.Error,
                    "{0}: Exception in FromCustomValues: {1}",
                    typeof(SledLuaVarLookUpType), ex.Message);

                return null;
            }
        }
Ejemplo n.º 4
0
        public static SledLuaVarLookUpType FromCustomValues(SledLuaVarScopeType scope, SledLuaVarLookUpContextType context, IList <SledLuaVarNameTypePairType> namesAndTypes)
        {
            try
            {
                var lookUp =
                    new DomNode(SledLuaSchema.SledLuaVarLookUpType.Type)
                    .As <SledLuaVarLookUpType>();

                lookUp.Scope   = scope;
                lookUp.Context = context;

                foreach (var nameAndType in namesAndTypes)
                {
                    lookUp.NamesAndTypes.Add((SledLuaVarNameTypePairType)nameAndType.Clone());
                }

                lookUp.Index      = 0;
                lookUp.StackLevel = 0;

                return(lookUp);
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLineDebug(
                    SledMessageType.Error,
                    "{0}: Exception in FromCustomValues: {1}",
                    typeof(SledLuaVarLookUpType), ex.Message);

                return(null);
            }
        }