예제 #1
0
    private Sio.SData format_map(IntPtr L, int index, NParam o)
    {
        Sio.SMapWriter pmap = new Sio.SMapWriter();
        Sio.SData      data = new Sio.SData(pmap);

        if (LuaAPI.lua_istable(L, index) && o.DType == ParamType.ptype_object)
        {
            NStruct ps = NStructManager.GetInstance().Find(o.TypeName);
            if (ps != null)
            {
                LuaAPI.lua_pushnil(L);
                while (LuaAPI.lua_next(L, index) != 0)
                {
                    if (LuaAPI.lua_isstring(L, -2))
                    {
                        NParam findparam = ps.Get(LuaAPI.lua_tostring(L, -2));
                        if (findparam != null)
                        {
                            pmap.write(findparam.Id, format_data(findparam, L, LuaAPI.lua_gettop(L), true));
                        }
                    }
                    LuaAPI.lua_pop(L, 1);
                }
            }
        }
        return(data);
    }
예제 #2
0
    private Sio.SData format_data(NParam o, RealStatePtr L, int index, bool checklist)
    {
        if (checklist == true && o.Container == ParamContainer.pparam_container_list)
        {
            return(format_List(L, index, o));
        }
        else
        {
            switch (o.DType)
            {
            case ParamType.ptype_bool:
            {
                bool ans = LuaAPI.lua_toboolean(L, index);
                if (LuaAPI.lua_isboolean(L, index))
                {
                    ans = LuaAPI.lua_toboolean(L, index);
                }
                return(new Sio.SData(ans));
            }

            case ParamType.ptype_char:
            case ParamType.ptype_uchar:
            {
                byte ans = 0;
                if (LuaAPI.lua_isnumber(L, index))
                {
                    ans = (byte)LuaAPI.xlua_tointeger(L, index);
                }
                return(new Sio.SData(ans));
            }

            case ParamType.ptype_ushort:
            {
                UInt16 ans = 0;
                if (LuaAPI.lua_isnumber(L, index))
                {
                    ans = (UInt16)LuaAPI.xlua_tointeger(L, index);
                }
                return(new Sio.SData(ans));
            }

            case ParamType.ptype_short:
            {
                Int16 ans = 0;
                if (LuaAPI.lua_isnumber(L, index))
                {
                    ans = (Int16)LuaAPI.xlua_tointeger(L, index);
                }
                return(new Sio.SData(ans));
            }

            case ParamType.ptype_int:
            {
                int ans = 0;
                if (LuaAPI.lua_isnumber(L, index))
                {
                    ans = (int)LuaAPI.xlua_tointeger(L, index);
                }
                return(new Sio.SData(ans));
            }

            case ParamType.ptype_uint:
            {
                uint ans = 0;
                if (LuaAPI.lua_isnumber(L, index))
                {
                    ans = (uint)LuaAPI.xlua_tointeger(L, index);
                }
                return(new Sio.SData(ans));
            }

            case ParamType.ptype_float:
            {
                float ans = 0.0f;
                if (LuaAPI.lua_isnumber(L, index))
                {
                    ans = (float)LuaAPI.xlua_tointeger(L, index);
                }
                return(new Sio.SData(ans));
            }

            case ParamType.ptype_double:
            {
                double ans = 0.0;
                if (LuaAPI.lua_isnumber(L, index))
                {
                    ans = (double)LuaAPI.xlua_tointeger(L, index);
                }
                return(new Sio.SData(ans));
            }

            case ParamType.ptype_long:
            {
                long ans = 0;
                if (LuaAPI.lua_isint64(L, index))
                {
                    ans = LuaAPI.lua_toint64(L, index);
                }
                return(new Sio.SData(ans));
            }

            case ParamType.ptype_ulong:
            {
                ulong ans = 0;
                if (LuaAPI.lua_isint64(L, index))
                {
                    ans = LuaAPI.lua_touint64(L, index);
                }
                return(new Sio.SData(ans));
            }

            case ParamType.ptype_string:
            {
                string ans = string.Empty;
                if (LuaAPI.lua_isstring(L, index))
                {
                    ans = LuaAPI.lua_tostring(L, index);
                }
                return(new Sio.SData(ans));
            }

            case ParamType.ptype_object:
            {
                return(format_map(L, index, o));
            }

            default:
                break;
            }
        }
        return(null);
    }