Пример #1
0
    static int ValueParamList(RealStatePtr L)
    {
        string parameterName;

        Contents.ValueType valueType = Contents.ValueType.String;
        try
        {
            int paramCount = LuaAPI.lua_gettop(L);
            parameterName = LuaAPI.lua_tostring(L, 2);
            valueType     = (Contents.ValueType)LuaAPI.lua_tonumber(L, 3);
        }
        catch (Exception e)
        {
            return(LuaAPI.luaL_error(L, "c# exception:" + e));
        }
        contents.ValueParameterList(parameterName, valueType);
        if (recordedBehaviour)
        {
            callRecords.Add(() =>
            {
                contents.ValueParameterList(parameterName, valueType);
            });
        }
        return(0);
    }
Пример #2
0
    static int ValueParam(RealStatePtr L)
    {
        string parameterName = "";

        Contents.ValueType valueType    = Contents.ValueType.String;
        string             defaultValue = "";

        try {
            int paramCount = LuaAPI.lua_gettop(L);
            if (paramCount == 3)
            {
                parameterName = LuaAPI.lua_tostring(L, 2);
                valueType     = (Contents.ValueType)LuaAPI.lua_tonumber(L, 3);
            }
            else if (paramCount == 4)
            {
                parameterName = LuaAPI.lua_tostring(L, 2);
                valueType     = (Contents.ValueType)LuaAPI.lua_tonumber(L, 3);
                defaultValue  = LuaAPI.lua_tostring(L, 4);
            }
        }
        catch (Exception e)
        {
            return(LuaAPI.luaL_error(L, "c# exception:" + e));
        }
        if (string.IsNullOrEmpty(defaultValue))
        {
            switch (valueType)
            {
            case Contents.ValueType.String:
                contents.StringProperty(parameterName);
                if (recordedBehaviour)
                {
                    callRecords.Add(() =>
                    {
                        contents.StringProperty(parameterName);
                    });
                }
                break;

            case Contents.ValueType.Number:
                double number = contents.NumberProperty(parameterName);
                if (recordedBehaviour)
                {
                    callRecords.Add(() =>
                    {
                        contents.NumberProperty(parameterName);
                    });
                }
                try
                {
                    LuaAPI.lua_pushnumber(L, number);
                    return(1);
                }
                catch (Exception e)
                {
                    return(LuaAPI.luaL_error(L, "c# exception:" + e));
                }

            case Contents.ValueType.Boolean:
                bool boolean = contents.BooleanProperty(parameterName);
                if (recordedBehaviour)
                {
                    callRecords.Add(() =>
                    {
                        contents.BooleanProperty(parameterName);
                    });
                }
                try
                {
                    LuaAPI.lua_pushboolean(L, boolean);
                    return(1);
                }
                catch (Exception e)
                {
                    return(LuaAPI.luaL_error(L, "c# exception:" + e));
                }

            case Contents.ValueType.Color:
                contents.ColorProperty(parameterName);
                if (recordedBehaviour)
                {
                    callRecords.Add(() =>
                    {
                        contents.ColorProperty(parameterName);
                    });
                }
                break;

            case Contents.ValueType.Vector3:
                contents.Vector3Property(parameterName);
                if (recordedBehaviour)
                {
                    callRecords.Add(() =>
                    {
                        contents.Vector3Property(parameterName);
                    });
                }
                break;

            case Contents.ValueType.Vector2:
                contents.Vector2Property(parameterName);
                if (recordedBehaviour)
                {
                    callRecords.Add(() =>
                    {
                        contents.Vector2Property(parameterName);
                    });
                }
                break;

            case Contents.ValueType.Vector4:
                contents.Vector4Property(parameterName);
                if (recordedBehaviour)
                {
                    callRecords.Add(() =>
                    {
                        contents.Vector4Property(parameterName);
                    });
                }
                break;
            }
        }
        else
        {
            switch (valueType)
            {
            case Contents.ValueType.String:
                contents.StringProperty(parameterName, defaultValue);
                if (recordedBehaviour)
                {
                    callRecords.Add(() =>
                    {
                        contents.StringProperty(parameterName, defaultValue);
                    });
                }
                break;

            case Contents.ValueType.Number:
                double number = contents.NumberProperty(parameterName, defaultValue);
                if (recordedBehaviour)
                {
                    callRecords.Add(() =>
                    {
                        contents.NumberProperty(parameterName, defaultValue);
                    });
                }
                try
                {
                    LuaAPI.lua_pushnumber(L, number);
                    return(1);
                }
                catch (Exception e)
                {
                    return(LuaAPI.luaL_error(L, "c# exception:" + e));
                }

            case Contents.ValueType.Boolean:
                bool boolean = contents.BooleanProperty(parameterName, defaultValue);
                if (recordedBehaviour)
                {
                    callRecords.Add(() =>
                    {
                        contents.BooleanProperty(parameterName, defaultValue);
                    });
                }
                try
                {
                    LuaAPI.lua_pushboolean(L, boolean);
                    return(1);
                }
                catch (Exception e)
                {
                    return(LuaAPI.luaL_error(L, "c# exception:" + e));
                }

            case Contents.ValueType.Color:
                contents.ColorProperty(parameterName, defaultValue);
                if (recordedBehaviour)
                {
                    callRecords.Add(() =>
                    {
                        contents.ColorProperty(parameterName, defaultValue);
                    });
                }
                break;

            case Contents.ValueType.Vector3:
                contents.Vector3Property(parameterName, defaultValue);
                if (recordedBehaviour)
                {
                    callRecords.Add(() =>
                    {
                        contents.Vector3Property(parameterName, defaultValue);
                    });
                }
                break;

            case Contents.ValueType.Vector2:
                contents.Vector2Property(parameterName, defaultValue);
                if (recordedBehaviour)
                {
                    callRecords.Add(() =>
                    {
                        contents.Vector2Property(parameterName, defaultValue);
                    });
                }
                break;

            case Contents.ValueType.Vector4:
                contents.Vector4Property(parameterName, defaultValue);
                if (recordedBehaviour)
                {
                    callRecords.Add(() =>
                    {
                        contents.Vector4Property(parameterName, defaultValue);
                    });
                }
                break;
            }
        }
        return(0);
    }