public string Register(string id, Closure func) { if (string.IsNullOrEmpty(id)) { throw new ArgumentException(nameof(id)); } if (func == null) { throw new ArgumentNullException(nameof(func)); } object LateBoundMethod(params object[] args) { var list = new List <object> { Instance }; var objs = LuaParser.Parse(args, Instance.OwnerScript); list.AddRange(objs); return(func.Call(list.ToArray()).ToObject()); } RpcRegister.RegisterMethod(id, LateBoundMethod); return(id); }
public Server(string id, RawMessageManager rawMessageManager, ModuleManager moduleManager, CacheManager cacheManager, ControllerComponentManager controllerComponentManager) { if (string.IsNullOrEmpty(id)) { throw new ArgumentException(nameof(id)); } ID = id; LuaHelper.RegisterType <Server>(); _moduleManager = moduleManager ?? throw new ArgumentNullException(nameof(moduleManager)); _cacheManager = cacheManager ?? throw new ArgumentNullException(nameof(cacheManager)); _controllerComponentManager = controllerComponentManager ?? throw new ArgumentNullException(nameof(controllerComponentManager)); _rawMessageManager = rawMessageManager ?? throw new ArgumentNullException(nameof(rawMessageManager)); _events = new Dictionary <string, Action <IUser, object> >(); _serverSocket = new ServerSocket(id); _serverSocket.Accepted += AcceptConnected; _serverSocket.Connected += PeerConnected; _serverSocket.Disconnected += PeerDisconnected; RpcRegister.RegisterMethod(this); RpcMethodIds = new List <string>(); RpcPacketTypes = new List <string>(); }
public string Register(string id, dynamic func, PythonHelper pythonHelper) { if (string.IsNullOrEmpty(id)) { throw new ArgumentException(nameof(id)); } if (func == null) { throw new ArgumentNullException(nameof(func)); } object LateBoundMethod(params object[] args) { var objs = PythonParser.Parse(args); return(pythonHelper.Call(func, objs)); } RpcRegister.RegisterMethod(id, LateBoundMethod); return(id); }