public object Visit(Import stmt) { string libname = (string)((Literal)(stmt.library)).value; //load another file instead if (libname.Length > 4 && libname.Substring(libname.Length - 4) == ".toy") { #if TOY_UNITY libname = Application.streamingAssetsPath + "/" + libname; #endif Environment env = Runner.RunFile(libname); //merge the sub-environment into this one, possibly under an alias environment.Define(stmt.alias != null ? ((Variable)stmt.alias).name.lexeme : null, env, true); return(null); } //try a bunch of different names Type type = null; if (type == null) { type = Type.GetType("Toy.Plugin." + libname); } if (type == null) //user plugins take precedence over built-in libraries { type = Type.GetType("Toy.Library." + libname); } //still not found if (type == null) { throw new ErrorHandler.RuntimeError(stmt.keyword, "Unexpected library name"); } //create the library and cast it to the correct type dynamic library = ((IPlugin)Convert.ChangeType(Activator.CreateInstance(type), type)).Singleton; //initialize the library library.Initialize(environment, stmt.alias != null ? ((Variable)stmt.alias).name.lexeme : null); return(null); }
//creation/destruction methods (unity glue functions) void Awake() { environment = new Environment(); environment.Define("this", new PluginExtras.GameObjectWrapper(this.gameObject), true); if (!System.String.IsNullOrEmpty(toyScript)) { RunFile(toyScript); } }
//creation/destruction methods (unity glue functions) void Awake() { environment = new Environment(); environment.Define("this", new GameObjectWrapper(this.gameObject), true); if (!String.IsNullOrEmpty(toyScript)) { RunFile(toyScript); } Runner.Run(environment, GetPropertyMethod("Awake", 0), new List <object>()); }
//creation/destruction methods (unity glue functions) void Awake() { //TODO: need a way to connect different Toy environments between multiple ToyBehaviours and ToyInterfaces (cleanly) environment = new Environment(); environment.Define("this", new PluginExtras.GameObjectWrapper(this.gameObject), true); if (!System.String.IsNullOrEmpty(toyScript)) { RunFile(toyScript); } Runner.Run(environment, GetPropertyMethod("Awake", 0), new List <object>()); }
public object Call(Interpreter interpreter, Token token, List <object> arguments) { Environment environment = new Environment(closure); for (int i = 0; i < declaration.parameters.Count; i++) { environment.Define(((Variable)declaration.parameters[i]).name.lexeme, arguments[i], false); } try { interpreter.ExecuteBlock(new Block(declaration.body, false), environment, true); } catch (ReturnException e) { return(e.result); } return(null); }