Exemplo n.º 1
0
        public bool Load(string filePath)
        {
            this.mFilePath = filePath;
            string content = XFile.ReadTextFile(this.mFilePath);

            this.mContents = XTableExchange.lua.StringToTable(XCSharp.EncodeUTF8(content));
            if (this.mContents == null)
            {
                this.mContents = new XTable();
            }
            return(true);
        }
Exemplo n.º 2
0
        public int PushValue(object o)
        {
            if (o == null)
            {
                mLuaState.PushNil();
                return(1);
            }

            Type t = o.GetType();

            switch (t.FullName)
            {
            case "System.Boolean":
            {
                mLuaState.PushBoolean((bool)o);
                return(1);
            }

            case "System.Char":
            {
                mLuaState.PushString(((char)o).ToString());
                return(1);
            }

            case "System.Byte":
            {
                mLuaState.PushNumber((byte)o);
                return(1);
            }

            case "System.SByte":
            {
                mLuaState.PushNumber((sbyte)o);
                return(1);
            }

            case "System.Int16":
            {
                mLuaState.PushNumber((short)o);
                return(1);
            }

            case "System.UInt16":
            {
                mLuaState.PushNumber((ushort)o);
                return(1);
            }

            case "System.Int32":
            {
                mLuaState.PushNumber((int)o);
                return(1);
            }

            case "System.UInt32":
            {
                mLuaState.PushNumber((uint)o);
                return(1);
            }

            case "System.Int64":
            {
                mLuaState.PushUInt64((ulong)o);
                return(1);
            }

            case "System.UInt64":
            {
                mLuaState.PushUInt64((ulong)o);
                return(1);
            }

            case "System.Single":
            {
                mLuaState.PushNumber((float)o);
                return(1);
            }

            case "System.Double":
            {
                mLuaState.PushNumber((double)o);
                return(1);
            }

            case "System.Decimal":
            {
                mLuaState.PushLightUserData((decimal)o);
                return(1);
            }

            case "System.String":
            {
                string utf8 = XCSharp.EncodeUTF8(o as string);
                mLuaState.PushString(utf8);
                return(1);
            }

            case "System.Object":
            {
                mLuaState.PushLightUserData((object)o);
                return(1);
            }

            case "XTable":
            {
                mLuaState.NewTable();
                XTable table = o as XTable;
                foreach (string key in table.Nodes.Keys)
                {
                    object val = table.Nodes[key];
                    this.PushValue(key);
                    this.PushValue(val);

                    mLuaState.RawSet(-3);
                }
                mLuaState.RawSet(-3);

                return(1);
            }

            default:
            {
                mLuaState.PushLightUserData((object)o);
                return(1);
            }
            }
        }