public static object Load(RubyScope/*!*/ scope, RubyModule/*!*/ self, MutableString/*!*/ libraryName) { object loaded; scope.RubyContext.Loader.LoadFile(null, self, libraryName, LoadFlags.ResolveLoaded | LoadFlags.AnyLanguage, out loaded); Debug.Assert(loaded != null); return loaded; }
public static object EachObject(BlockParam block, RubyModule/*!*/ self, [NotNull]RubyClass/*!*/ theClass) { Type classType = theClass.GetType(); bool isClass = (classType == typeof(RubyClass)); if (!isClass && classType != typeof(RubyModule)) { throw new NotSupportedException("each_object only supported for objects of type Class or Module"); } if (block == null) { throw RubyExceptions.NoBlockGiven(); } Dictionary<RubyModule, object> visited = new Dictionary<RubyModule, object>(); Stack<RubyModule> modules = new Stack<RubyModule>(); modules.Push(theClass.Context.ObjectClass); while (modules.Count > 0) { RubyModule next = modules.Pop(); RubyClass asClass = next as RubyClass; if (!isClass || asClass != null) { object result; if (block.Yield(next, out result)) { return result; } } next.EnumerateConstants(delegate(RubyModule module, string name, object value) { RubyModule constAsModule = (value as RubyModule); if (constAsModule != null && !visited.ContainsKey(constAsModule)) { modules.Push(constAsModule); visited[module] = null; } return false; }); } return visited.Count; }
public static object Dump(WriterSites/*!*/ sites, RubyModule/*!*/ self, object obj, [NotNull]RubyIO/*!*/ io, [Optional]int? limit) { BinaryWriter writer = io.GetBinaryWriter(); MarshalWriter dumper = new MarshalWriter(sites, writer, self.Context, limit); dumper.Dump(obj); return io; }
public static void choose(RubyModule/*!*/ self, params object[] args) { try { if (args != null && args.Length != 4 && args.Length != 5) throw RubyExceptionData.InitializeException(new RuntimeError("wrong number of arguments"), "wrong number of arguments"); if (args.Length == 5) m_opaque = args[4].ToString(); m_fmt = int.Parse(args[3].ToString()); m_callback = args[0].ToString(); m_title = args[1].ToString(); //long init = args[2].toRubyTime().getTime(); RHODESAPP().MainPage.Dispatcher.BeginInvoke(() => { OpenPickerPage(); }); } catch (Exception ex) { Exception rubyEx = self.Context.CurrentException; if (rubyEx == null) { rubyEx = RubyExceptionData.InitializeException(new RuntimeError(ex.Message.ToString()), ex.Message); } LOG.ERROR("choose", ex); throw rubyEx; } }
public static bool AreIdentical(ConversionStorage<MutableString>/*!*/ toPath, RubyModule/*!*/ self, object path1, object path2) { FileSystemInfo info1, info2; return RubyFileOps.RubyStatOps.TryCreate(self.Context, self.Context.DecodePath(Protocols.CastToPath(toPath, path1)), out info1) && RubyFileOps.RubyStatOps.TryCreate(self.Context, self.Context.DecodePath(Protocols.CastToPath(toPath, path2)), out info2) && RubyFileOps.RubyStatOps.AreIdentical(self.Context, info1, info2); }
public static bool AreIdentical(RubyModule/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path1, [DefaultProtocol, NotNull]MutableString/*!*/ path2) { FileSystemInfo info1, info2; return RubyFileOps.RubyStatOps.TryCreate(self.Context, self.Context.DecodePath(path1), out info1) && RubyFileOps.RubyStatOps.TryCreate(self.Context, self.Context.DecodePath(path2), out info2) && RubyFileOps.RubyStatOps.AreIdentical(self.Context, info1, info2); }
public RubyEventInfo(EventTracker/*!*/ tracker, RubyMemberFlags flags, RubyModule/*!*/ declaringModule, bool isDetached) : base(flags, declaringModule) { Assert.NotNull(tracker, declaringModule); _tracker = tracker; _isDetached = isDetached; }
// copy ctor private RubyMethodGroupInfo(RubyMethodGroupInfo/*!*/ info, RubyMemberFlags flags, RubyModule/*!*/ module) : base(info.MethodBases, flags, module) { _isStatic = info._isStatic; _hasVirtuals = info._hasVirtuals; _staticDispatchMethods = info._staticDispatchMethods; // Note: overloadOwners and maxCachedOverloadLevel are cleared whenever the group is copied. }
internal RubyLambdaMethodInfo(Proc/*!*/ block, string/*!*/ definitionName, RubyMemberFlags flags, RubyModule/*!*/ declaringModule) : base(flags, declaringModule) { Assert.NotNull(block, definitionName, declaringModule); _lambda = block.ToLambda(this); _definitionName = definitionName; _id = Interlocked.Increment(ref _Id); }
internal UnboundMethod(RubyModule/*!*/ targetConstraint, string/*!*/ name, RubyMemberInfo/*!*/ info) { Assert.NotNull(targetConstraint, name, info); _name = name; _info = info; _targetConstraint = targetConstraint; }
public MethodResolutionResult(RubyMemberInfo/*!*/ info, RubyModule/*!*/ owner, bool visible) { Assert.NotNull(info, owner); _info = info; _owner = owner; _visible = visible; }
public static Object get_property_by_name(RubyModule/*!*/ self, [NotNull]String/*!*/ name) { if(name == "platform") return "WP7"; else if(name == "os_version") return "7.0"; else if(name == "country") return "us"; else return ""; }
protected RubyClass/*!*/ DefineGlobalClass(string/*!*/ name, Type/*!*/ type, RubyClass/*!*/ super, Action<RubyModule> instanceTrait, Action<RubyModule> classTrait, RubyModule[]/*!*/ mixins, Delegate[] factories) { RubyClass result = _context.DefineLibraryClass(name, type, instanceTrait, classTrait, super, mixins, factories, _builtin); _context.ObjectClass.SetConstant(result.Name, result); return result; }
protected RubyMethodGroupBase(OverloadInfo/*!*/[] methods, RubyMemberFlags flags, RubyModule/*!*/ declaringModule) : base(flags, declaringModule) { if (methods != null) { SetMethodBasesNoLock(methods); } }
internal RubyOverloadGroupInfo(OverloadInfo/*!*/[]/*!*/ methods, RubyModule/*!*/ declaringModule, RubyOverloadGroupInfo/*!*/[] overloadOwners, bool isStatic) : base(methods, declaringModule, isStatic) { Debug.Assert(overloadOwners == null || methods.Length == overloadOwners.Length); _overloadOwners = overloadOwners; }
protected RubyAttributeAccessorInfo(RubyMemberFlags flags, RubyModule/*!*/ declaringModule, string/*!*/ variableName) : base(flags, declaringModule) { Assert.NotEmpty(variableName); Debug.Assert(variableName.StartsWith("@")); _instanceVariableName = variableName; }
public static object dosync_source(RubyModule/*!*/ self, [NotNull]object/*!*/ srcID) { object res = null; try { int nSrcID = 0; String strName = ""; if (srcID is long) nSrcID = (int)(long)srcID; else if (srcID is int) nSrcID = (int)srcID; else strName = srcID.ToString(); SyncThread.getInstance().addQueueCommand(new SyncThread.SyncCommand(SyncThread.scSyncOne, strName, nSrcID, true)); res = SyncThread.getInstance().getRetValue(); } catch (Exception ex) { Exception rubyEx = self.Context.CurrentException; if (rubyEx == null) { rubyEx = RubyExceptionData.InitializeException(new RuntimeError(ex.Message.ToString()), ex.Message); } LOG.ERROR("dosync_source", ex); throw rubyEx; } return res; }
public RubyFieldInfo(FieldInfo/*!*/ fieldInfo, RubyMemberFlags flags, RubyModule/*!*/ declaringModule, bool isSetter, bool isDetached) : base(flags, declaringModule) { Assert.NotNull(fieldInfo, declaringModule); _fieldInfo = fieldInfo; _isSetter = isSetter; _isDetached = isDetached; }
public static object dosync(RubyModule/*!*/ self, RubyArray args) { object res = null; try { boolean bShowStatus = true; String query_params = ""; if ( args != null && args.Count > 0 ) { String str = ((MutableString)args[0]).ToString(); //bShowStatus = args[0].Equals(RubyConstant.QTRUE)||"true".equalsIgnoreCase(str); bShowStatus = "true".equalsIgnoreCase(str); } if (args != null && args.Count > 1) query_params = ((MutableString)args[1]).ToString(); SyncThread.getInstance().addQueueCommand(new SyncThread.SyncCommand(SyncThread.scSyncAll, bShowStatus, query_params)); res = SyncThread.getInstance().getRetValue(); } catch (Exception ex) { Exception rubyEx = self.Context.CurrentException; if (rubyEx == null) { rubyEx = RubyExceptionData.InitializeException(new RuntimeError(ex.Message.ToString()), ex.Message); } LOG.ERROR("dosync", ex); throw rubyEx; } return res; }
/// <summary> /// Creates a Ruby method implemented by a method group of CLR methods. /// </summary> internal RubyLibraryMethodInfo(LibraryOverload/*!*/[]/*!*/ overloads, RubyMemberFlags flags, RubyModule/*!*/ declaringModule) : base(null, flags, declaringModule) { Assert.NotNullItems(overloads); Assert.NotEmpty(overloads); _overloads = overloads; }
public static decimal InducedFrom(RubyModule/*!*/ self, [NotNull]BigInteger value) { try { return (decimal)value; } catch (OverflowException) { throw RubyExceptions.CreateRangeError("number too big to convert into System::Decimal"); } }
// method: internal RubyMethodInfo(RubyMethodBody/*!*/ body, RubyScope/*!*/ declaringScope, RubyModule/*!*/ declaringModule, RubyMemberFlags flags) : base(flags, declaringModule) { Assert.NotNull(body, declaringModule); _body = body; _declaringScope = declaringScope; }
public static object GetClassVariable(RubyModule/*!*/ self, [DefaultProtocol]string/*!*/ variableName) { object value; if (self.TryResolveClassVariable(variableName, out value) == null) { RubyUtils.CheckClassVariableName(variableName); throw RubyExceptions.CreateNameError(String.Format("uninitialized class variable {0} in {1}", variableName, self.Name)); } return value; }
// copy ctor private RubyMethodGroupInfo(RubyMethodGroupInfo/*!*/ info, RubyMemberFlags flags, RubyModule/*!*/ module) : base(info.MethodBases, flags, module) { _isStatic = info._isStatic; _hasVirtuals = info._hasVirtuals; _staticDispatchMethods = info._staticDispatchMethods; // Note: overloadOwners and maxCachedOverloadLevel are cleared whenever the group is copied // The resulting group captures an immutable set of underlying CLR members. }
public static object GetTaggedClasses(RubyModule/*!*/ self) { object taggedClasses; if (!self.TryGetClassVariable(_TaggedClasses, out taggedClasses)) { taggedClasses = CreateDefaultTagMapping(self.Context); self.SetClassVariable(_TaggedClasses, taggedClasses); } return taggedClasses; }
public static object AddBuiltinType( [NotNull]BlockParam/*!*/ block, RubyModule/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ typeTag) { // Add a stub implementation to unblock Rails 3 Console.WriteLine("WARNING: YAML.add_builtin_type is not implemented"); return null; }
protected RubyModule/*!*/ DefineGlobalModule(string/*!*/ name, Type/*!*/ type, int restrictions, Action<RubyModule> instanceTrait, Action<RubyModule> classTrait, Action<RubyModule> constantsInitializer, RubyModule/*!*/[]/*!*/ mixins) { RubyModule result = _context.DefineLibraryModule(name, type, instanceTrait, classTrait, constantsInitializer, mixins, (ModuleRestrictions)restrictions, _builtin); PublishModule(name, result); return result; }
/// <summary> /// Creates a CLR method group. /// </summary> internal RubyMethodGroupInfo(MethodBase/*!*/[]/*!*/ methods, RubyModule/*!*/ declaringModule, RubyMethodGroupInfo/*!*/[] overloadOwners, bool isStatic) : base(methods, RubyMemberFlags.Public, declaringModule) { Debug.Assert(overloadOwners == null || methods.Length == overloadOwners.Length); _isStatic = isStatic; _overloadOwners = overloadOwners; }
internal RubyMemberInfo(RubyMemberFlags flags, RubyModule/*!*/ declaringModule) { Assert.NotNull(declaringModule); Debug.Assert(flags != RubyMemberFlags.Invalid); _flags = flags; _declaringModule = declaringModule; }
protected RubyClass/*!*/ DefineGlobalClass(string/*!*/ name, Type/*!*/ type, int restrictions, RubyClass/*!*/ super, Action<RubyModule> instanceTrait, Action<RubyModule> classTrait, Action<RubyModule> constantsInitializer, RubyModule/*!*/[]/*!*/ mixins, params Delegate[] factories) { RubyClass result = _context.DefineLibraryClass(name, type, instanceTrait, classTrait, constantsInitializer, super, mixins, factories, (ModuleRestrictions)restrictions, _builtin); PublishModule(name, result); return result; }
public static object Evaluate([NotNull] BlockParam /*!*/ block, RubyModule /*!*/ self) { return(RubyUtils.EvaluateInModule(self, block, null)); }
public static object Execute([NotNull] BlockParam /*!*/ block, RubyModule /*!*/ self, params object[] /*!*/ args) { return(RubyUtils.EvaluateInModule(self, block, args)); }
public static object ClassVariableSet(RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ variableName, object value) { self.Context.CheckClassVariableName(variableName); self.SetClassVariable(variableName, value); return(value); }
public static RubyArray /*!*/ GetProtectedInstanceMethods(RubyModule /*!*/ self) { return(GetProtectedInstanceMethods(self, true)); }
public static RubyModule /*!*/ AliasMethod(RubyContext /*!*/ context, RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ newName, [DefaultProtocol, NotNull] string /*!*/ oldName) { self.AddMethodAlias(newName, oldName); return(self); }
public static bool CaseEquals(RubyModule /*!*/ self, object other) { return(self.Context.IsKindOf(other, self)); }
public static object ConstantMissing(RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ name) { return(self.Context.ResolveMissingConstant(self, name)); }
public static object InducedFrom(UnaryOpStorage /*!*/ tofStorage, RubyModule /*!*/ self, [NotNull] BigInteger /*!*/ value) { var site = tofStorage.GetCallSite("to_f"); return(site.Target(site, value)); }
public static double InducedFrom(RubyModule /*!*/ self, object value) { throw RubyExceptions.CreateTypeError("failed to convert {0} into Float", self.Context.GetClassDisplayName(value)); }
public static void AttrWriter(RubyScope /*!*/ scope, RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ name) { DefineAccessor(scope, self, name, false, true); }
public static object SetConstantValue(RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ constantName, object value) { self.Context.CheckConstantName(constantName); RubyUtils.SetConstant(self, constantName, value); return(value); }
internal static MutableString /*!*/ ToS(RubyContext /*!*/ context, string /*!*/ methodName, RubyModule /*!*/ declaringModule, RubyModule /*!*/ targetModule, string /*!*/ classDisplayName) { MutableString result = MutableString.CreateMutable(context.GetIdentifierEncoding()); result.Append("#<"); result.Append(classDisplayName); result.Append(": "); if (ReferenceEquals(targetModule, declaringModule)) { result.Append(declaringModule.GetDisplayName(context, true)); } else { result.Append(targetModule.GetDisplayName(context, true)); result.Append('('); result.Append(declaringModule.GetDisplayName(context, true)); result.Append(')'); } result.Append('#'); result.Append(methodName); result.Append('>'); return(result); }
public static object ExtendObject(RubyModule /*!*/ self, object extendedObject) { // include self into extendedObject's singleton self.Context.GetOrCreateSingletonClass(extendedObject).IncludeModules(self); return(extendedObject); }
protected RubyClass /*!*/ GetClass(Type /*!*/ type) { Debug.Assert(type != null && !RubyModule.IsModuleType(type)); // TODO: CLR class vs library class: return(_context.GetOrCreateClass(type)); }
private static bool SkipDefinition(RubyModule /*!*/ module, int attributes) { return((RubyCompatibility)(attributes >> RubyMethodAttribute.CompatibilityEncodingShift) > module.Context.RubyOptions.Compatibility); }
public static object Included(RubyContext /*!*/ context, RubyModule /*!*/ self, RubyModule /*!*/ includedIn) { includedIn.SingletonClass.DefineLibraryMethod("induced_from", (int)RubyMethodAttributes.PublicSingleton, new Func <RubyModule, object, object>(InducedFrom)); return(self); }
public static object InvalidComparison(RubyModule /*!*/ self, object module) { throw RubyExceptions.CreateTypeError("compared with non class/module"); }
// thread-safe: public static void SetConstant(RubyModule /*!*/ module, string /*!*/ name, object value) { module.SetConstant(name, value); }
public static object GetConstantValue(RubyScope /*!*/ scope, RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ constantName) { return(RubyUtils.GetConstant(scope.GlobalScope, self, constantName, true)); }
public static RubyArray /*!*/ GetProtectedInstanceMethods(RubyModule /*!*/ self, bool inherited) { return(GetMethods(self, inherited, RubyMethodAttributes.ProtectedInstance)); }
public static RubyArray /*!*/ GetGlobalConstants(RubyModule /*!*/ self) { return(GetDefinedConstants(self.Context.ObjectClass)); }
public static object Included(RubyContext /*!*/ context, RubyModule /*!*/ self, RubyModule /*!*/ includedIn) { var singleton = includedIn.GetOrCreateSingletonClass(); singleton.AddMethod( context, "induced_from", new RubyLibraryMethodInfo( new[] { LibraryOverload.Create(new Func <RubyModule, object, object>(InducedFrom), false, 0, 0) }, RubyMethodVisibility.Public, singleton ) ); return(self); }
public static object Comparison(RubyModule /*!*/ self, object module) { return(null); }
private static object InducedFrom(RubyModule /*!*/ rubyClass, object other) { throw RubyExceptions.CreateTypeError("undefined conversion from {0} into {1}", rubyClass.Context.GetClassOf(other).Name, rubyClass.Name); }
public static bool Equals(RubyModule /*!*/ self, object other) { return(ReferenceEquals(self, other)); }
public static void ObjectExtended(RubyModule /*!*/ self, object extendedObject) { // extendedObject has been extended by self, i.e. self has been included into extendedObject's singleton class }
public static double InducedFrom(RubyModule /*!*/ self, double value) { return(value); }
public static MutableString GetAutoloadedConstantPath(RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ constantName) { return(self.GetAutoloadedConstantPath(constantName)); }
public static object InducedFrom(UnaryOpStorage /*!*/ tofStorage, RubyModule /*!*/ self, int value) { var site = tofStorage.GetCallSite("to_f"); return(site.Target(site, ScriptingRuntimeHelpers.Int32ToObject(value))); }
public static void Attr(RubyScope /*!*/ scope, RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ name, [Optional] bool writable) { DefineAccessor(scope, self, name, true, writable); }