Пример #1
0
        public bool Invoke(string method, params object[] args)
        {
            try
            {
                InternalHandle h = engine.GlobalObject.GetProperty(method);
                if (h.IsError)
                {
                    Logger.LogError("[V8] Failed to invoke " + method);
                    return(false);
                }
                if (h.IsFunction)
                {
                    InternalHandle[] handles = new InternalHandle[args.Length];
                    for (int i = 0; i < args.Length; ++i)
                    {
                        handles.SetValue(engine.CreateValue(args[i]), i);
                    }

                    h.Call(handles);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("[V8] Plugin error: " + pluginInfo.Name + " (" + pluginInfo.Author + ")\nJavascript error:\n " + ex.Message + "\n----\nStack trace:\n" + ex.StackTrace);
                Logger.LogError("[V8] Invoking method: " + method + "\nParams (" + args.Length + "):");
                for (int i = 0; i < args.Length; ++i)
                {
                    Logger.LogError(i + "=>" + args[i].GetType());
                }
                return(false);
            }
            return(false);
        }