tolua#的Examples-10_Enum

    string script =
        @"
            space = nil

            function TestEnum(e)        
                print('Enum is:'..tostring(e))        

                if space:ToInt() == 0 then
                    print('enum ToInt() is ok')                
                end

                if not space:Equals(0) then
                    print('enum compare int is ok')                
                end

                if space == e then
                    print('enum compare enum is ok')
                end

                local s = UnityEngine.Space.IntToEnum(0)

                if space == s then
                    print('IntToEnum change type is ok')
                end
            end

            function ChangeLightType(light, type)
                print('change light type to Directional')
                light.type = UnityEngine.LightType.Directional
            end
        ";

    void Start ()
    {
        LuaState state = new LuaState();
        state.Start();
        LuaBinder.Bind(state);

        state.DoString(script);
        state["space"] = Space.World;

        LuaFunction func = state.GetFunction("TestEnum");
        func.BeginPCall();
        func.Push(Space.World);
        func.PCall();
        func.EndPCall();
        func.Dispose();
        func = null;

        GameObject go = GameObject.Find("/Light");
        Light light = go.GetComponent();
        func = state.GetFunction("ChangeLightType");
        func.BeginPCall();
        func.Push(light);
        func.Push(LightType.Directional);
        func.PCall();
        func.EndPCall();
        func.Dispose();
        func = null;

        state.CheckTop();
        state.Dispose();
        state = null;
    }

这个例子主要演示lua如何访问c#中的枚举类型,这也是开发中必不可少的一环,function TestEnum(e)      函数里面详细的演示了枚举类型的各种操作,space:ToInt()、space:Equals(0)、还有在ulua里面并不存在的功能:local s = UnityEngine.Space.IntToEnum(0),这里面都具备了。

[本日志由 admin 于 2016-03-20 09:42 PM 更新]
上一篇: tolua#的Examples-09_Dictionary
下一篇: tolua#的Examples-11_Delegate
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭