• tolua反射应用


    tolua反射应用

    有时候要修改紧急bug或者增加一个新功能,但又不能更新整包。C#代码没有导出wrap,可以临时用一下tolua的反射。

    C#代码:

    namespace MyNameSpace
    {
        public class ToluaReflection
        {
            public string StringField = "ToluaReflection";
        }
    }
    

    lua代码:

    function toLuaReflectionTest()
        require 'tolua.reflection'
        tolua.loadassembly('Assembly-CSharp')
        local reflectionTest = typeof("MyNameSpace.ToluaReflection")
        local instance = tolua.createinstance(reflectionTest)
        local BindingFlags = System.Reflection.BindingFlags
        local flag = System.Reflection.BindingFlags.GetMask( BindingFlags.Public , BindingFlags.NonPublic , BindingFlags.Static , BindingFlags.Instance)
        local pubfield = tolua.getfield(reflectionTest, "StringField", flag)
        local pubfieldValue = pubfield:Get(instance)
        print(pubfieldValue)
        pubfield:Set(instance, "changedpubfield")
        pubfieldValue = pubfield:Get(instance)
        print(pubfieldValue)
    end
    

    运行结果:

    参考博文:https://blog.csdn.net/zoujiandong_8888/article/details/83585213

  • 相关阅读:
    元素查找
    寂寞的堆
    爱丽丝·玛格特罗依德
    排序的代价
    数字串
    我心永恒
    滑动窗口
    魔法猪学院
    曦皓的幸运数
    曦皓的旅游
  • 原文地址:https://www.cnblogs.com/woodjay/p/12608017.html
Copyright © 2020-2023  润新知