New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
反射调用c#类的私有方法 #46
Comments
MethodBase关于Invoke的定义: 下面那个是子类实现的,而反射找到的是子类,里头只有下面那个方法,换言之,按目前xLua的实现你访问MonoMethodInfo实例只能调用到下面那个。 是个问题,但其实也不建议你反射直接在lua里头做,在C#封装一下,提供个更简单的接口给lua更合适些。 稍后我提供一下 |
我决定提供一个api,设置一下后,所有private的东东可用。 |
设置某类 |
原来是这样,谢谢!期待您的更新! |
使用很方便,谢谢! |
xlua.private_accessible(CS.HotfixTest) |
@mydodolookdo 我试了ok,代码贴一下?报啥错呢? |
刚才重新生成code编译了之后,没有报错可以访问私有变量了,不好意思。 |
有c#方法
public class A{ void foo(int x) { } }
想在lua通过反射
MethodInfo.Invoke(Object obj, Object[] params)
调用:
method:Invoke(obj, { 2017 })
但是传参的时候报错了,求指点:
LuaException: c# exception:invalid obj for System.Reflection.BindingFlags,stack: at XLua.ObjectCasters+c__AnonStorey59.<>m__B1 (IntPtr L, Int32 idx, System.Object target) [0x00000] in :0
at XLua.OverloadMethodWrap.Call (IntPtr L) [0x00000] in :0
at XLua.MethodWrap.Call (IntPtr L) [0x00000] in :0
stack traceback:
[C]: in method 'Invoke'
[string "chunk"]:17: in function <[string "chunk"]:9>
XLua.LuaEnv.ThrowExceptionFromError (Int32 oldTop)
XLua.DelegateBridge.SystemVoid (XLua.LuaTable self) (at Assets/XLua/Gen/UnityEngineBoundsWrap.cs:539)
The text was updated successfully, but these errors were encountered: