public static void require(ExternalFunction function) { try { String path = (String)function.load_var("path").type_cast(Types.String); SiBtyVirtualMachine _vitural_machine = new SiBtyVirtualMachine(); Space current_space = function.parent_space as Space; foreach (string external_function in current_space.external_methods) { var ex_func = current_space.variables[external_function] as ExternalFunction; ex_func.parent_space = _vitural_machine.root_space; _vitural_machine.set_extension_inheritance(external_function, ex_func); } _vitural_machine.load_from_file(path._value); foreach (var variable in _vitural_machine.root_space.variables) { if (!current_space.variables.ContainsKey(variable.Key)) { current_space.variables[variable.Key] = variable.Value; } } foreach (string external_function in current_space.external_methods) { var ex_func = current_space.variables[external_function] as ExternalFunction; ex_func.parent_space = current_space; } function.set_return_value(new Planguage.Boolean(true)); } catch { Console.Error.WriteLine("Error occurred when loading modules"); function.set_return_value(new Planguage.Boolean(false)); } }
public static void set_title(ExternalFunction function) { String title = (String)function.load_var("title").type_cast(Types.String); Console.Title = title._value; function.set_return_value(new Boolean(true)); }
public static void write(ExternalFunction function) { String text = (String)function.load_var("text").type_cast(Types.String); Console.Write(text._value); function.set_return_value(text); }
public static void sort(ExternalFunction f) { /* * var array = [5,3,3,6,3,56] * array = array_sort(array , do x,y * return y-x * end) * print array */ Array array = (Array)f.load_var("array").type_cast(Types.Array); BaseFunction comparisor = (BaseFunction)f.load_var("comparisor").type_cast(Types.Function); array._value.Sort((x, y) => { comparisor.set_params(new SibtyObject[] { y, x }); Number result = (Number)comparisor.function_call().type_cast(Types.Number); return(result._value); }); f.set_return_value(array); }
public static void create(ExternalFunction self) { Planguage.vm.Prototypes.Object @object = new Prototypes.Object(); BaseFunction _func = self.load_var("function").type_cast(Types.Function) as BaseFunction; var param_numbers = _func.number_of_params; if (param_numbers < 1) { throw new Planguage.Errors.ParameterError(true); } System.Collections.Generic.List <SibtyObject> _params = new System.Collections.Generic.List <SibtyObject>() { @object }; for (var i = 1; i < param_numbers; i++) { _params.Add(new NilClass()); } _func.set_params(_params.ToArray()); self.set_return_value(_func.function_call()); }
public static void read_number(ExternalFunction f) { var number = Convert.ToInt32(Console.ReadLine()); f.set_return_value(new Number(number)); }
public static void readline(ExternalFunction func) { string _input = Console.ReadLine(); func.set_return_value(new String(_input)); }
public static void clear(ExternalFunction func) { func.set_return_value(new NilClass()); System.Console.Clear(); }
public static void length(ExternalFunction f) { Array array = (Array)f.load_var("array").type_cast(Types.Array); f.set_return_value(new Number(array._value.Count)); }
public static void new_line(ExternalFunction function) { function.set_return_value(new Planguage.String("\n")); }