示例#1
0
        public static LuaValue Byte(LuaValue[] values)
        {
            LuaString str = values[0] as LuaString;
            LuaNumber startNumber = values.Length > 1 ? values[1] as LuaNumber : null;
            LuaNumber endNumber = values.Length > 2 ? values[2] as LuaNumber : null;

            int start = startNumber == null ? 1 : (int)startNumber.Number;
            int end = endNumber == null ? start : (int)endNumber.Number;

            LuaValue[] numbers = new LuaValue[end - start + 1];
            for (int i = 0; i < numbers.Length; i++)
            {
                numbers[i] = new LuaNumber (char.ConvertToUtf32(str.Text, start - 1 + i) );
            }

            return new LuaMultiValue(numbers);
        }
示例#2
0
        public void SetKeyValue(LuaValue key, LuaValue value)
        {
            LuaNumber number = key as LuaNumber;

            if (number != null && number.Number == (int)number.Number)
            {
                int index = (int)number.Number;

                if (index == this.Length + 1)
                {
                    this.AddValue(value);
                    return;
                }

                if (index > 0 && index <= this.Length)
                {
                    foreach (LuaValue v in table.Keys)
                    {
                        if (((v as LuaNumber) != null) && (int.Parse((v as LuaNumber).Number.ToString()) == index))
                        {
                            table[v] = value;
                            return;
                        }
                    }
                    //this.list[index - 1] = value;
                    //return;
                }
            }

            if (value == LuaNil.Nil)
            {
                this.RemoveKey(key);
                return;
            }

            if (this.table == null)
            {
                this.table = new Dictionary <LuaValue, LuaValue>();
            }

            this.table[key] = value;
        }
示例#3
0
        public LuaValue GetValue(LuaValue key)
        {
            if (key == LuaNil.Nil)
            {
                return(LuaNil.Nil);
            }
            else
            {
                LuaNumber number = key as LuaNumber;

                if (number != null && number.Number == (int)number.Number)
                {
                    int index = (int)number.Number;
                    //index--; //Convert to C# index

                    if (index > 0 && index <= this.Length)
                    {
                        foreach (LuaValue v in table.Keys)
                        {
                            if (((v as LuaNumber) != null) && (int.Parse((v as LuaNumber).Number.ToString()) == index))
                            {
                                return(table[v]);
                            }
                        }
                        //return this.list[index - 1];
                    }
                }
                else if (this.table != null && this.table.ContainsKey(key))
                {
                    return(this.table[key]);
                }
                else if (this.MetaTable != null)
                {
                    // pass to meta table function
                    return(this.GetValueFromMetaTable(key));
                }

                return(LuaNil.Nil);
            }
        }