public void changeTo(LuaConstant constant, bool isGlobal = false)
        {
            this.globalValue = isGlobal;
            this.value       = constant.value;

            this.type = constant.type;
        }
Beispiel #2
0
        private void readConstants()
        {
            this.constantCount = this.inputReader.ReadInt32();
            // Create array for constants
            this.Constants = new LuaConstant[this.constantCount];
            // Go through all constants
            for (int i = 0; i < this.constantCount; i++)
            {
                // Make a new constant object
                LuaConstant constant = new LuaConstant();
                // Read the type of constant
                constant.type = (Datatype.Type) this.inputReader.ReadByte();
                // Check if its a constant we can read
                switch (constant.type)
                {
                case Datatype.Type.Nil:
                    constant.value = "nil";
                    break;

                case Datatype.Type.Boolean:
                    constant.value = (this.inputReader.ReadByte() == 1) ? "true" : "false";
                    break;

                case Datatype.Type.Number:
                    var formatted = this.inputReader.ReadSingle();
                    if (formatted % 1 == 0)
                    {
                        constant.value = ((int)formatted).ToString();
                    }
                    else
                    {
                        constant.value = formatted.ToString("0.000000000");
                    }
                    break;

                case Datatype.Type.String:
                    int stringLength = this.inputReader.ReadInt32();
                    constant.value = this.inputReader.ReadNullTerminatedString();
                    break;

                case Datatype.Type.XHash:
                    // TODO : Add support for switch to string
                    constant.value = String.Format("0x{0:X}", this.inputReader.ReadUInt64() & 0xFFFFFFFFFFFFFFF);
                    break;

                default:
                    constant.value = "Unknown constant type";
                    break;
                }
                // Add it to the array
                this.Constants[i] = constant;
            }
        }