Ejemplo n.º 1
0
        private Loader(NetRuby rb)
        {
            ruby = rb;
            loadPath = new RArray(rb, true);
            features = new RArray(rb, true);

            string baseDir = AppDomain.CurrentDomain.BaseDirectory;
            loadPath.Add(baseDir);
            loadPath.Add(Path.Combine(baseDir, "lib"));
            loadPath.Add(AppDomain.CurrentDomain.BaseDirectory);
            string lp = Environment.GetEnvironmentVariable("RUBYLIB");
            if (lp != null)
            {
                string[] sp = lp.Split(new char[] { Path.PathSeparator });
                for (int i = 0; i < sp.Length; i++)
                {
                    loadPath.Add(Environment.ExpandEnvironmentVariables(sp[i]));
                }
            }
            /*
            if (rb.SafeLevel == 0)
            {
            */
                loadPath.Add(".");
            /*
            }
            */
        }
Ejemplo n.º 2
0
        private Loader(NetRuby rb)
        {
            ruby     = rb;
            loadPath = new RArray(rb, true);
            features = new RArray(rb, true);

            string baseDir = AppDomain.CurrentDomain.BaseDirectory;

            loadPath.Add(baseDir);
            loadPath.Add(Path.Combine(baseDir, "lib"));
            loadPath.Add(AppDomain.CurrentDomain.BaseDirectory);
            string lp = Environment.GetEnvironmentVariable("RUBYLIB");

            if (lp != null)
            {
                string[] sp = lp.Split(new char[] { Path.PathSeparator });
                for (int i = 0; i < sp.Length; i++)
                {
                    loadPath.Add(Environment.ExpandEnvironmentVariables(sp[i]));
                }
            }

            /*
             * if (rb.SafeLevel == 0)
             * {
             */
            loadPath.Add(".");

            /*
             * }
             */
        }
Ejemplo n.º 3
0
 public RArray Indices(object[] args)
 {
     RArray ary = new RArray(ruby, true);
     for (int i = 0; i < args.Length; i++)
     {
         ary.Add(hash[args[i]]);
     }
     return ary;
 }
Ejemplo n.º 4
0
        public RArray Indices(object[] args)
        {
            RArray ary = new RArray(ruby, true);

            for (int i = 0; i < args.Length; i++)
            {
                ary.Add(hash[args[i]]);
            }
            return(ary);
        }
Ejemplo n.º 5
0
        internal void IncPush(string lp)
        {
            string baseDir = AppDomain.CurrentDomain.BaseDirectory;

            string[] sp = lp.Split(new char[] { Path.PathSeparator });
            for (int i = 0; i < sp.Length; i++)
            {
                if (loadPath.Contains(sp[i]) == false)
                {
                    loadPath.Add(Environment.ExpandEnvironmentVariables(sp[i]));
                }
            }
        }
Ejemplo n.º 6
0
        public override RArray ToArray()
        {
            bool            b = IsTainted;
            RArray          a = new RArray(ruby, true);
            GroupCollection g = match.Groups;

            for (int i = 0; i < g.Count; i++)
            {
                string s = g[i].Value;
                if (b)
                {
                    a.Add(new RString(ruby, s, b));
                }
                else
                {
                    a.Add(s);
                }
            }
            if (b)
            {
                a.Taint();
            }
            return(a);
        }
Ejemplo n.º 7
0
        public RArray Collect()
        {
            if (ruby.IsBlockGiven == false)
            {
                return((RArray)Clone());
            }
            RArray collect = new RArray(ruby, ptr.Count);

            lock (ptr.SyncRoot)
            {
                foreach (object o in ptr)
                {
                    collect.Add(ruby.Yield(o));
                }
            }
            return(collect);
        }
Ejemplo n.º 8
0
 public RArray Collect()
 {
     if (ruby.IsBlockGiven == false)
         return (RArray)Clone();
     RArray collect = new RArray(ruby, ptr.Count);
     lock (ptr.SyncRoot)
     {
         foreach (object o in ptr)
         {
             collect.Add(ruby.Yield(o));
         }
     }
     return collect;
 }
Ejemplo n.º 9
0
        internal bool Require(string s)
        {
            RThread th = ruby.GetCurrentContext();

            ////ruby.CheckSafeString(th, s);
            s = s.Replace('/', Path.DirectorySeparatorChar);
            string fname  = null;
            bool   script = true;
            string ext    = Path.GetExtension(s);

            if (ext != String.Empty)
            {
                if (String.Compare(ext, ".rb", true) == 0)
                {
                    fname = FindFile(s);
                }
                else if (String.Compare(ext, ".dll", true) == 0 ||
                         String.Compare(ext, ".so", true) == 0)
                {
                    fname  = FindFile(s);
                    script = false;
                }
            }
            else
            {
                for (int i = 0; i < exts.Length; i++)
                {
                    fname = FindFile(s + exts[i]);
                    if (fname != null)
                    {
                        if (i != 0)
                        {
                            script = false;
                        }
                        break;
                    }
                }
            }
            if (fname == null)
            {
                throw new eLoadError("No such file to load -- " + s);
            }

            string fileName = Path.GetFileName(fname);

            if (featureCheck(fileName))
            {
                return(false);
            }

            if (script == false)
            {
                try
                {
                    AssemblyName asm = AssemblyName.GetAssemblyName(fname);
                    Assembly     a   = Assembly.Load(asm);
                    Type[]       tps = a.GetTypes();
                    foreach (Type t in tps)
                    {
                        AddType(t, th);
                    }
                    features.Add(fileName);
                }
                catch (FileLoadException)
                {
                    return(false);
                }
                catch (BadImageFormatException)
                {
                    throw new eLoadError("Not valid file image to load -- " + fname);
                }
            }
            else
            {
                ////int oldSafeLevel = th.safeLevel;
                ////th.safeLevel = 0;
                ////th.PushTag(Tag.TAG.PROT_NONE);
                try
                {
                    ruby.Load(fname, false);
                    features.Add(fileName);
                }
                catch (Exception e)
                {
#if _DEBUG
                    System.Console.Error.WriteLine(e.Message);
                    System.Console.Error.WriteLine(e.StackTrace);
#endif
                    throw e;
                }
                finally
                {
                    ////th.PopTag(true);
                    ////th.safeLevel = oldSafeLevel;
                }
            }
            return(true);
        }
Ejemplo n.º 10
0
 public override RArray ToArray()
 {
     bool b = IsTainted;
     RArray a = new RArray(ruby, true);
     GroupCollection g = match.Groups;
     for (int i = 0; i < g.Count; i++)
     {
         string s = g[i].Value;
         if (b)
             a.Add(new RString(ruby, s, b));
         else
             a.Add(s);
     }
     if (b)
         a.Taint();
     return a;
 }