Exemple #1
0
        /// <summary>
        /// Add a native function to the interpreter
        /// </summary>
        /// <param name="name">Name of the function</param>
        /// <param name="function">Function object to be called</param>
        public void AddNativeFunction(string name, NativeFunction function)
        {
            function.Name = name;
            NativeFunctionSymbol symbol = new NativeFunctionSymbol(name, GlobalScope, function);

            GlobalScope.Define(symbol);
            CommitableScope g = GlobalScope as CommitableScope;

            g?.CommitScope();
        }
Exemple #2
0
 /// <summary>
 /// Loads native functions inside the assembly dynamially
 /// </summary>
 private void AddInternalNativeFunctions()
 {
     foreach (Type t in GetType().Assembly.GetTypes())
     {
         if (t.IsSubclassOf(typeof(NativeFunction)))
         {
             ConstructorInfo ctor = t.GetConstructor(new Type[] {});
             if (ctor != null)
             {
                 NativeFunction instance = (NativeFunction)ctor.Invoke(new object[] {});
                 AddNativeFunction(t.Name, instance);
             }
         }
     }
 }
 public NativeFunctionSymbol(string name, IScope parentScope, NativeFunction nativeFunction) : base(name, parentScope)
 {
     NativeFunction = nativeFunction;
 }