Beispiel #1
0
        public static void Delete(LanguageInterpreter sender, FunctionArgs args)
        {
            if (EUtils.CheckArgs(1, args))
            {
                object param = args.EvaluateParameters()[0];

                if (EUtils.CheckArgType(param, typeof(string)))
                {
                    string filepath = (string)param;

                    if (File.Exists(filepath))
                    {
                        File.Delete(filepath);
                    }
                    else
                    {
                        sender.Interpreter.HandleException(new Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "Error deleting file.", "The specified file does not exist.", ""));
                    }
                }
                else
                {
                    sender.Interpreter.HandleException(new Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "Invalid parameter type.", "Function expects parameter of type 'String', got '" + param.GetType().Name + "'.", ""));
                }
            }
            else
            {
                sender.Interpreter.HandleException(Consts.Exceptions.ParameterCountMismatch(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, 1));
            }
        }
Beispiel #2
0
 private static void InitializeSymbols(LanguageInterpreter interpreter)
 {
     interpreter.Add("glob is I");
     interpreter.Add("prok is V");
     interpreter.Add("pish is X");
     interpreter.Add("tegj is L");
 }
Beispiel #3
0
        public static void Create(LanguageInterpreter sender, FunctionArgs args)
        {
            if (EUtils.CheckArgs(1, args))
            {
                object param = args.EvaluateParameters()[0];

                if (EUtils.CheckArgType(param, typeof(string)))
                {
                    string filepath = (string)param;

                    if (!File.Exists(filepath))
                    {
                        // could just use .Dispose(); ...
                        using (File.Create(filepath)) { }
                    }
                    else
                    {
                        sender.Interpreter.HandleException(new Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "Error creating file.", "A file already exists at the specified path.", ""));
                    }
                }
                else
                {
                    sender.Interpreter.HandleException(new Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "Invalid parameter type.", "Function expects parameter of type 'String', got '" + param.GetType().Name + "'.", ""));
                }
            }
            else
            {
                sender.Interpreter.HandleException(Consts.Exceptions.ParameterCountMismatch(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, 1));
            }
        }
Beispiel #4
0
        void json_parse(LanguageInterpreter sender, FunctionArgs args)
        {
            if (EUtils.CheckArgs(1, args))
            {
                object param = args.EvaluateParameters()[0];

                if (EUtils.CheckArgType(param, typeof(string)))
                {
                    string json_str = (string)param;

                    dynamic parsed_json = DynamicJson.Parse(json_str);

                    if (parsed_json.IsArray)
                    {
                        AnonymousVariableArray finalArray = VariableArrayFromDynamic(parsed_json);

                        args.HasResult = true;
                        args.Result    = finalArray;
                    }
                    else
                    {
                        sender.Interpreter.HandleException(new Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "Unimplemented", "Only arrays are implemented in the JSON parser.", ""));
                    }
                }
                else
                {
                    sender.Interpreter.HandleException(new Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "Invalid parameter type.", "Function expects parameter of type 'String', got '" + param.GetType().Name + "'.", ""));
                }
            }
            else
            {
                sender.Interpreter.HandleException(Consts.Exceptions.ParameterCountMismatch(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, 1));
            }
        }
Beispiel #5
0
        void requestroute_get(LanguageInterpreter sender, FunctionArgs args)
        {
            if (EUtils.CheckArgs(2, args))
            {
                object param  = args.EvaluateParameters()[0];
                object param2 = args.EvaluateParameters()[1];

                /**/

                if (EUtils.CheckArgType(param, typeof(string)))
                {
                    if (EUtils.CheckArgType(param2, typeof(UserFunction)) || EUtils.CheckArgType(param2, typeof(String)))
                    {
                        string relative_path = (string)param;

                        //sender.Interpreter.HandleException(new AzLang.Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "info: new get request handler [" + relative_path + "]", "detail", "dunno"));

                        if (EUtils.CheckArgType(param2, typeof(UserFunction)))
                        {
                            UserFunction handler = (UserFunction)param2;

                            routedHTTPInterpreterServer.RequestHandlers.Add(relative_path, new RequestHandler(handler, RequestMethod.GET, relative_path));
                        }
                        else
                        {
                            string file = (string)param2;

                            if (!System.IO.File.Exists(file) && !System.IO.Directory.Exists(file))
                            {
                                sender.Interpreter.HandleException(new AzLang.Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "File or folder non-existent", "The specified file or folder '" + file + "' does not exist.", "Check the file path provided for errors."));
                            }
                            else
                            {
                                routedHTTPInterpreterServer.RequestHandlers.Add(relative_path, new RequestHandler(file, RequestMethod.GET, relative_path));
                            }
                        }
                    }
                    else
                    {
                        sender.Interpreter.HandleException(new AzLang.Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "Invalid parameter type.", "Function expects parameter of type 'UserFunction' or 'String', got '" + param2.GetType().Name + "'.", ""));
                    }
                }
                else
                {
                    sender.Interpreter.HandleException(new AzLang.Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "Invalid parameter type.", "Function expects parameter of type 'String', got '" + param.GetType().Name + "'.", ""));
                }
            }
            else
            {
                sender.Interpreter.HandleException(Consts.Exceptions.ParameterCountMismatch(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, 1));
            }
        }
Beispiel #6
0
        public static void Exists(LanguageInterpreter sender, FunctionArgs args)
        {
            if (EUtils.CheckArgs(1, args))
            {
                object param = args.EvaluateParameters()[0];

                if (EUtils.CheckArgType(param, typeof(string)))
                {
                    args.HasResult = true;
                    args.Result    = File.Exists((string)param);
                }
                else
                {
                    sender.Interpreter.HandleException(new Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "Invalid parameter type.", "Function expects parameter of type 'String', got '" + param.GetType().Name + "'.", ""));
                }
            }
            else
            {
                sender.Interpreter.HandleException(Consts.Exceptions.ParameterCountMismatch(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, 1));
            }
        }
Beispiel #7
0
        public static void Append(LanguageInterpreter sender, FunctionArgs args)
        {
            if (EUtils.CheckArgs(2, args))
            {
                object param  = args.EvaluateParameters()[0];
                object param2 = args.EvaluateParameters()[1];

                if (EUtils.CheckArgType(param, typeof(string)))
                {
                    if (EUtils.CheckArgType(param2, typeof(string)))
                    {
                        string filepath = (string)param;
                        string text     = (string)param2;

                        if (File.Exists(filepath))
                        {
                            args.HasResult = true;
                            File.AppendAllText(filepath, text);
                        }
                        else
                        {
                            sender.Interpreter.HandleException(new Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "Error appending to file.", "The specified file does not exist.", ""));
                        }
                    }
                    else
                    {
                        sender.Interpreter.HandleException(new Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "Invalid parameter type.", "Function expects parameter of type 'String', got '" + param2.GetType().Name + "'.", ""));
                    }
                }
                else
                {
                    sender.Interpreter.HandleException(new Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "Invalid parameter type.", "Function expects parameter of type 'String', got '" + param.GetType().Name + "'.", ""));
                }
            }
            else
            {
                sender.Interpreter.HandleException(Consts.Exceptions.ParameterCountMismatch(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, 1));
            }
        }
Beispiel #8
0
        void json_stringify(LanguageInterpreter sender, FunctionArgs args)
        {
            if (EUtils.CheckArgs(1, args))
            {
                object param = args.EvaluateParameters()[0];

                if (EUtils.CheckArgType(param, typeof(AnonymousVariableArray)))
                {
                    AnonymousVariableArray array = (AnonymousVariableArray)param;

                    args.HasResult = true;
                    args.Result    = array.SerializeToJSON();
                }
                else
                {
                    sender.Interpreter.HandleException(new Exception(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, "Invalid parameter type.", "Function expects parameter of type 'AnonymousVariableArray', got '" + param.GetType().Name + "'.", ""));
                }
            }
            else
            {
                sender.Interpreter.HandleException(Consts.Exceptions.ParameterCountMismatch(sender.Interpreter.CurrentFile, sender.Interpreter.CurrentLine, 1));
            }
        }
Beispiel #9
0
 private static void InitializeCommodities(LanguageInterpreter interpreter)
 {
     interpreter.Add("glob glob Silver is 34 Credits");
     interpreter.Add("glob prok Gold is 57800 Credits");
     interpreter.Add("pish pish Iron is 3910 Credits");
 }