public void Push(GLua GLua, Object obj) { if (obj is Delegate dele) { Int32 cfunc(IntPtr L) { List <Object> args = new List <Object>(); foreach (ParameterInfo param in dele.Method.GetParameters()) { args.Add(GLua.Get(param.ParameterType, param.Position + 1)); } Object rtn = dele.DynamicInvoke(args.ToArray()); if (rtn != null) { GLua.Push(rtn, rtn.GetType()); return(1); } return(0); } #pragma warning disable IDE0009 // Member access should be qualified. will post issue on forums GLua.PushCFunction(cfunc); #pragma warning restore IDE0009 } else { throw new Exception("wrapper func must be castable to delegate"); } }
public void Push(GLua GLua, object obj) { if (obj is Delegate dele) { CFunc cfunc = (IntPtr L) => { List <object> args = new List <object>(); foreach (var param in dele.Method.GetParameters()) { args.Add(GLua.Get(param.ParameterType, param.Position + 1)); } var rtn = dele.DynamicInvoke(args.ToArray()); if (rtn != null) { GLua.Push(rtn, rtn.GetType()); return(1); } return(0); }; GCHandle gch = GCHandle.Alloc(cfunc); GLua.AddLuaReference(gch); GLua.PushCFunction(cfunc); } else { throw new Exception("wrapper func must be castable to delegate"); } }
public void Push(GLua GLua, Object obj) { if (obj is CFunc func) { GLua.PushCFunction(func); } }