Git Product home page Git Product logo

Comments (5)

chexiongsheng avatar chexiongsheng commented on May 19, 2024 1

谢谢反馈,NestedType确实没支持。已经增加,请更新下代码。
另外,xlua.hotfix第一个参数新增字符串的支持,和C#的Type.GetType规则一样,如果NestedType是非public的,就必须得用字符串来表示。

from xlua.

chexiongsheng avatar chexiongsheng commented on May 19, 2024

支持的

from xlua.

lizhengde avatar lizhengde commented on May 19, 2024

刚才写错lua代码了,删了重新发一下,点击Hotfix按钮时,就报下面的错

错误日志:

LuaException: exception in xlua.access: System.NullReferenceException: Object reference not set to an instance of an object
  at XLua.StaticLuaCallbacks.XLuaAccess (IntPtr L) [0x00001] in C:\Users\Seven\Downloads\xLua-master\xLua\Assets\XLua\Src\Utils.cs:419 
stack traceback:
	[C]: in field 'access'
	[string "Init"]:86: in field 'hotfix'
	[string "chunk"]:2: in main chunk
XLua.LuaEnv.ThrowExceptionFromError (Int32 oldTop)
XLua.LuaEnv.DoString (System.String chunk, System.String chunkName, XLua.LuaTable env) (at Assets/XLua/Src/MethodWarpsCache.cs:254)
TestForXLuaHotfix.OnGUI () (at Assets/Scripts/TestForXLuaHotfix.cs:24)

Hotfix操作代码

public class TestForXLuaHotfix : MonoBehaviour {
    LuaEnv luaEnv = new LuaEnv();

    void OnGUI()
    {
        //['TestOutterClass+TestInnerClass']
        if(GUI.Button(new Rect(10, 100, 300, 150), "Hotfix"))
        {
            luaEnv.DoString(@"
                    xlua.hotfix(CS['TestOutterClass+TestInnerClass'], 'Update', function(self)
                        self.tick = self.tick + 1
                        if(self.tick % 50) == 0 then
                            print('<<<<<<<< update in lua, tick = ' .. self.tick)
                        end
                    end)
                ");
        }
    }
}

两个类的代码

[Hotfix]
public class TestOutterClass : MonoBehaviour {
    TestInnerClass innerC = new TestInnerClass();

    void Update () {
        innerC.Update();
    }

    [Hotfix]
    public class TestInnerClass
    {
        public int tick = 1;

        public void Update()
        {
            if (++tick % 50 == 0)
            {
                Debug.Log("Update tick : " + tick);
            }
        }
    }
}

from xlua.

chexiongsheng avatar chexiongsheng commented on May 19, 2024

内置类直接用点:CS.TestOuterClass.TestInnerClass

from xlua.

lizhengde avatar lizhengde commented on May 19, 2024

直接使用点(CS.TestOutterClass.TestInnerClass)出现错误:

LuaException: xlua.access, no field __Hitfix0_Update
stack traceback:
	[C]: in field 'access'
	[string "Init"]:86: in field 'hotfix'
	[string "chunk"]:2: in main chunk
XLua.LuaEnv.ThrowExceptionFromError (Int32 oldTop) (at Assets/XLua/Src/LuaEnv.cs:360)
XLua.LuaEnv.DoString (System.String chunk, System.String chunkName, XLua.LuaTable env) (at Assets/XLua/Src/LuaEnv.cs:212)
TestForHotfix.OnGUI () (at Assets/Scripts/TestForHotfix.cs:23)

另外我发现一个问题,在Hotfix.cs中的HotfixInject函数里的assembly.modules[0].Types里面并没有TestInnerClass,不知道是不是这个原因,具体的我还没有深入看

from xlua.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.