Exemplo n.º 1
0
        //static methods
        static void Main(string[] args)
        {
            //get the app's name
            string appName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;

            switch (args.Length)
            {
            case 0:
                RunPrompt();
                break;

            case 1:
                if (Runner.RunFile(args[0]) == null)
                {
                    System.Environment.Exit(-1);
                }
                break;

            case 2:
                if (args[0] == "run")
                {
                    if (Runner.Run(args[1]) == null)
                    {
                        System.Environment.Exit(-1);
                    }
                }
                break;

            default:
                Console.Write($"Usage: {appName} [<file name> | run \"<toy code>\"]");
                break;
            }
        }
        //public script files
        public void RunFile(string fileName)
        {
            environment = Runner.RunFile(environment, Application.streamingAssetsPath + "/" + fileName + ".toy");

            if (environment == null)
            {
                throw new NullReferenceException("Environment is null in ToyBehaviour.RunFile()");
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 //creation/destruction methods
 void Awake()
 {
     environment = Runner.RunFile("Assets/" + toyScript + ".toy");
     Runner.Run(environment, $"const __instance = Unity.Fetch(\"{this.gameObject.name}\");");
     Runner.Run(environment, "__instance.Awake();");
 }