public override void Load(string code = "") { try { context = ScriptContext.CurrentContext; context.Include(rpath + "\\" + Name + ".php", true); Class = (PhpObject) context.NewObject(Name); PHPGlobals = context.GlobalVariables; context.GlobalVariables.Add("Commands", chatCommands); context.GlobalVariables.Add("DataStore", DataStore.GetInstance()); context.GlobalVariables.Add("Find", Find.GetInstance()); context.GlobalVariables.Add("GlobalData", GlobalData); context.GlobalVariables.Add("Plugin", this); context.GlobalVariables.Add("Server", Pluton.Server.GetInstance()); context.GlobalVariables.Add("ServerConsoleCommands", consoleCommands); context.GlobalVariables.Add("Util", Util.GetInstance()); context.GlobalVariables.Add("Web", Web.GetInstance()); context.GlobalVariables.Add("World", World.GetInstance()); foreach (var x in PHPGlobals) { Globals.Add(x.Key.ToString()); } State = PluginState.Loaded; } catch (Exception ex) { Logger.LogException(ex); State = PluginState.FailedToLoad; } PluginLoader.GetInstance().OnPluginLoaded(this); }
/// <summary> /// Creates new object with given class name, naming context and arguments and then wraps it into /// a duck type specified in generic type arguments. /// </summary> /// <typeparam name="T">Duck type interface to be used for wrapping.</typeparam> /// <param name="className">Class name which will be used for new object creation.</param> /// <param name="namingContext">Naming context.</param> /// <param name="ctorArguments">Constructor arguments to be used.</param> /// <returns>Dynamic object wrapped into static wrapper.</returns> public static T NewObject <T>(this ScriptContext context, string /*!*/ className, NamingContext namingContext, params object[] ctorArguments) { //create new argument array and dig wrapped values out of it object[] newCtorArgs = new object[ctorArguments.Length]; for (int i = 0; i < newCtorArgs.Length; i++) { IDuckType duck = ctorArguments[i] as IDuckType; if (duck != null) { newCtorArgs[i] = duck.OriginalObject; } else { newCtorArgs[i] = ctorArguments[i]; } } object o = context.NewObject(className, namingContext, newCtorArgs); return(DuckTyping.Instance.ImplementDuckType <T>(o)); }
/// <summary> /// Creates new object with given class name and arguments and then wraps it into /// a duck type specified in generic type arguments. /// </summary> /// <typeparam name="T">Duck type interface to be used for wrapping.</typeparam> /// <param name="className">Class name which will be used for new object creation.</param> /// <param name="ctorArguments">Constructor arguments to be used.</param> /// <returns>Dynamic object wrapped into static wrapper.</returns> public static T NewObject <T>(this ScriptContext context, string /*!*/ className, params object[] ctorArguments) { return(context.NewObject <T>(className, null, ctorArguments)); }