1、 Lua doString error: XLua.LuaException: xlua.access, no field __Hotfix0_ForwardReset
[LuaScriptMdl][xLua] Lua doString error: XLua.LuaException: xlua.access, no field __Hotfix0_ForwardReset
stack traceback:
[C]: in field 'access'
xluasrc:98: in field 'hotfix'
Lua/xlua/util:112: in function 'Lua.xlua.util.hotfix_ex'
Lua_GameFramework:10: in method 'InitHotfix'
Lua_GameMain:91: in method 'ReloadScript'
[string ""]:1: in main chunk
LuaEnv.cs:442
LuaEnv.cs:275
LuaEnv.cs:289
LuaScriptMdl.cs:569
Solution: ClearGenerated Code => Generated Code => Hotfix Inject In Editor re-inject again
2. How to write lambda expression in xlua
c#
()=> {
mUIMgr.CloseDialog(Type); }
xlua
function a()
local f2 = function ()
self.mUIMgr:CloseDialog(Type)
end
end
或
function a()
function f2()
self.mUIMgr:CloseDialog(Type)
end
end
(The risk of module leakage will be detected, but no leakage has been encountered yet)
3. xlua implementation entrusts the official Github link link
entrusted by xlua .
C#
public class TestClass
{
public void OnClickBtn(Object a)
{
}
}
public delegate void VoidDelegate(int a);
xlua
--把C#的函数赋值给一个委托字段
(参数含义是个人理解,欢迎指正)
--CS.VoidDelegate:public delegate void VoidDelegate(int a);
--obj:Event delegate's target object.(事件委托的目标对象);静态方法这里填nil
--CS.TestClass:类名
--OnClickBtn:方法名
--{
typeof(CS.System.Object)}:OnClickBtn方法参数类型
local func3 = util.createdelegate(CS.VoidDelegate , obj, CS.TestClass, 'OnClickBtn', {
typeof(CS.System.Object)})
-- description: 直接用C#函数创建delegate
local function createdelegate(delegate_cls, obj, impl_cls, method_name, parameter_type_list)
local flag = enum_or_op_ex(CS.System.Reflection.BindingFlags.Public, CS.System.Reflection.BindingFlags.NonPublic,
CS.System.Reflection.BindingFlags.Instance, CS.System.Reflection.BindingFlags.Static)
local m = parameter_type_list and typeof(impl_cls):GetMethod(method_name, flag, nil, parameter_type_list, nil)
or typeof(impl_cls):GetMethod(method_name, flag)
return CS.System.Delegate.CreateDelegate(typeof(delegate_cls), obj, m)
end
4. The parameter of the C# method rewritten by xlua has a delegate
c#
//声明
AddTimer(float, bool, Delegate d);
//调用
T.AddTimer(0.7f,false, PlayEffect);
xlua
function a()
local delegate = function ()
self:PlayEffect()
end
self.mTimerMdl:AddTimer(0.7, false, delegate)
end
5. The C# method called by xlua is an extension method.
xlua cannot be called through an instance like c#, but can only be called like a static method, namespace.class name.method
c#
//方法
namespace K
{
class L
{
AddTimer(this GameObject, string);
}
}
//调用
this.gameobject.AddTimer(string);
xlua
function a()
CS.K.L.AddTimer(GameObject, string);
end