本文整理汇总了C#中Ioke.Lang.IokeObject.Init方法的典型用法代码示例。如果您正苦于以下问题:C# IokeObject.Init方法的具体用法?C# IokeObject.Init怎么用?C# IokeObject.Init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ioke.Lang.IokeObject
的用法示例。
在下文中一共展示了IokeObject.Init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public override void Init(IokeObject obj)
{
Runtime runtime = obj.runtime;
IokeObject number = obj;
obj.Kind = "Number";
obj.Mimics(IokeObject.As(runtime.Mixins.GetCell(null, null, "Comparing"), obj), runtime.nul, runtime.nul);
IokeObject real = new IokeObject(runtime, "A real number can be either a rational number or a decimal number", new Number());
real.MimicsWithoutCheck(number);
real.Kind = "Number Real";
number.RegisterCell("Real", real);
IokeObject rational = new IokeObject(runtime, "A rational number is either an integer or a ratio", new Number());
rational.MimicsWithoutCheck(real);
rational.Kind = "Number Rational";
number.RegisterCell("Rational", rational);
IokeObject integer = new IokeObject(runtime, "An integral number", new Number());
integer.MimicsWithoutCheck(rational);
integer.Kind = "Number Integer";
number.RegisterCell("Integer", integer);
runtime.Integer = integer;
IokeObject ratio = new IokeObject(runtime, "A ratio of two integral numbers", new Number());
ratio.MimicsWithoutCheck(rational);
ratio.Kind = "Number Ratio";
number.RegisterCell("Ratio", ratio);
runtime.Ratio = ratio;
IokeObject _decimal = new IokeObject(runtime, "An exact, unlimited representation of a decimal number", new Decimal(BigDecimal.ZERO));
_decimal.MimicsWithoutCheck(real);
_decimal.Init();
number.RegisterCell("Decimal", _decimal);
IokeObject infinity = new IokeObject(runtime, "A value representing infinity", new Number(RatNum.infinity(1)));
infinity.MimicsWithoutCheck(ratio);
infinity.Kind = "Number Infinity";
number.RegisterCell("Infinity", infinity);
runtime.Infinity = infinity;
IokeObject infinity2 = new IokeObject(runtime, "A value representing infinity", new Number(RatNum.infinity(1)));
infinity2.MimicsWithoutCheck(ratio);
infinity2.Kind = "Number \u221E";
number.RegisterCell("\u221E", infinity2);
number.RegisterMethod(runtime.NewNativeMethod("returns a hash for the number",
new NativeMethod.WithNoArguments("hash", (method, context, message, on, outer) => {
outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
return context.runtime.NewNumber(Number.GetValue(on).GetHashCode());
})));
number.RegisterMethod(runtime.NewNativeMethod("returns the square root of the receiver. this should return the same result as calling ** with 0.5",
new NativeMethod.WithNoArguments("sqrt", (method, context, message, on, outer) => {
outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
RatNum value = Number.GetValue(on);
if(value is IntFraction) {
IntNum num = value.numerator();
IntNum den = value.denominator();
BigDecimal nums = new BigSquareRoot().Get(num.AsBigDecimal());
BigDecimal dens = new BigSquareRoot().Get(den.AsBigDecimal());
try {
num = IntNum.valueOf(nums.toBigIntegerExact().ToString());
den = IntNum.valueOf(dens.toBigIntegerExact().ToString());
return context.runtime.NewNumber(new IntFraction(num, den));
} catch(ArithmeticException e) {
// Ignore and fall through
}
}
if(RatNum.compare(value, IntNum.zero()) < 1) {
IokeObject condition = IokeObject.As(IokeObject.GetCellChain(context.runtime.Condition,
message,
context,
"Error",
"Arithmetic"), context).Mimic(message, context);
condition.SetCell("message", message);
condition.SetCell("context", context);
condition.SetCell("receiver", on);
context.runtime.ErrorCondition(condition);
}
return context.runtime.NewDecimal(new BigSquareRoot().Get(value.AsBigDecimal()));
})));
number.RegisterMethod(runtime.NewNativeMethod("returns true if the left hand side number is equal to the right hand side number.",
new TypeCheckingNativeMethod("==", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(runtime.Number)
.WithRequiredPositional("other")
.Arguments,
(method, on, args, keywords, context, message) => {
Number d = (Number)IokeObject.dataOf(on);
object other = args[0];
return ((other is IokeObject) &&
(IokeObject.dataOf(other) is Number)
&& (((d.kind || ((Number)IokeObject.dataOf(other)).kind) ? on == other :
d.value.Equals(((Number)IokeObject.dataOf(other)).value)))) ? context.runtime.True : context.runtime.False;
})));
//.........这里部分代码省略.........
示例2: Init
public override void Init(IokeObject obj)
{
Runtime runtime = obj.runtime;
obj.Kind = "Regexp";
IokeObject regexpMatch = new IokeObject(runtime, "contains behavior related to assignment", new RegexpMatch(obj, null, null));
regexpMatch.MimicsWithoutCheck(runtime.Origin);
regexpMatch.Init();
obj.RegisterCell("Match", regexpMatch);
obj.RegisterMethod(runtime.NewNativeMethod("returns a hash for the regexp",
new NativeMethod.WithNoArguments("hash", (method, context, message, on, outer) => {
outer.ArgumentsDefinition.CheckArgumentCount(context, message, on);
Regexp r = (Regexp)IokeObject.dataOf(on);
return context.runtime.NewNumber(r.pattern.GetHashCode() + 13 * r.flags.GetHashCode());
})));
obj.RegisterMethod(runtime.NewNativeMethod("returns true if the left hand side pattern is equal to the right hand side pattern.",
new TypeCheckingNativeMethod("==", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(runtime.Regexp)
.WithRequiredPositional("other")
.Arguments,
(method, on, args, keywords, context, message) => {
Regexp d = (Regexp)IokeObject.dataOf(on);
object other = args[0];
return ((other is IokeObject) &&
(IokeObject.dataOf(other) is Regexp) &&
((on == context.runtime.Regexp || other == context.runtime.Regexp) ? on == other :
(d.pattern.Equals(((Regexp)IokeObject.dataOf(other)).pattern) &&
d.flags.Equals(((Regexp)IokeObject.dataOf(other)).flags)))) ? context.runtime.True : context.runtime.False;
})));
obj.RegisterMethod(runtime.NewNativeMethod("Returns the pattern use for this regular expression",
new TypeCheckingNativeMethod.WithNoArguments("pattern", obj,
(method, on, args, keywords, context, message) => {
return context.runtime.NewText(GetPattern(on));
})));
obj.RegisterMethod(runtime.NewNativeMethod("Takes one argument and tries to match that argument against the current pattern. Returns nil if no match can be done, or a Regexp Match object if a match succeeds",
new TypeCheckingNativeMethod("match", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(obj)
.WithRequiredPositional("other")
.Arguments,
(method, on, args, keywords, context, message) => {
IokeObject target = IokeObject.As(Interpreter.Send(context.runtime.asText, context, args[0]), context);
string arg = Text.GetText(target);
Matcher m = ((Regexp)IokeObject.dataOf(on)).regexp.Matcher(arg);
if(m.Find()) {
IokeObject match = regexpMatch.AllocateCopy(message, context);
match.MimicsWithoutCheck(regexpMatch);
match.Data = new RegexpMatch(IokeObject.As(on, context), m, target);
return match;
} else {
return context.runtime.nil;
}
})));
obj.AliasMethod("match", "=~", null, null);
obj.RegisterMethod(runtime.NewNativeMethod("Takes one argument that should be a text and returns a text that has all regexp meta characters quoted",
new NativeMethod("quote", DefaultArgumentsDefinition.builder()
.WithRequiredPositional("text")
.Arguments,
(method, on, args, keywords, context, message) => {
return context.runtime.NewText(Pattern.Quote(Text.GetText(Interpreter.Send(context.runtime.asText, context, args[0]))));
})));
obj.RegisterMethod(runtime.NewNativeMethod("Takes one or two text arguments that describes the regular expression to create. the first text is the pattern and the second is the flags.",
new NativeMethod("from", DefaultArgumentsDefinition.builder()
.WithRequiredPositional("pattern")
.WithOptionalPositional("flags", "")
.Arguments,
(method, on, args, keywords, context, message) => {
string pattern = Text.GetText(Interpreter.Send(context.runtime.asText, context, args[0]));
string flags = "";
if(args.Count > 1) {
flags = Text.GetText(Interpreter.Send(context.runtime.asText, context, args[1]));
}
return context.runtime.NewRegexp(pattern, flags, context, message);
})));
obj.RegisterMethod(runtime.NewNativeMethod("Takes one argument and tries to match that argument against the current pattern. Returns a list of all the texts that were matched.",
new TypeCheckingNativeMethod("allMatches", TypeCheckingArgumentsDefinition.builder()
.ReceiverMustMimic(obj)
.WithRequiredPositional("other")
.Arguments,
(method, on, args, keywords, context, message) => {
string arg = Text.GetText(Interpreter.Send(context.runtime.asText, context, args[0]));
Matcher m = ((Regexp)IokeObject.dataOf(on)).regexp.Matcher(arg);
var result = new SaneArrayList();
MatchIterator iter = m.FindAll();
while(iter.HasMore) {
result.Add(runtime.NewText(iter.NextMatch.Group(0)));
}
return runtime.NewList(result);
//.........这里部分代码省略.........
示例3: Init
public static void Init(IokeObject obj)
{
Runtime runtime = obj.runtime;
obj.Kind = "FileSystem";
IokeObject file = new IokeObject(runtime, "represents a file in the file system", new IokeFile(null));
file.MimicsWithoutCheck(runtime.Io);
file.Init();
obj.RegisterCell("File", file);
obj.RegisterMethod(runtime.NewNativeMethod("Tries to interpret the given arguments as strings describing file globs, and returns an array containing the result of applying these globs.",
new NativeMethod("[]", DefaultArgumentsDefinition.builder()
.WithRest("globTexts")
.Arguments,
(method, context, message, on, outer) => {
var args = new SaneArrayList();
outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
var dirs = FileSystem.Glob(context.runtime, Text.GetText(args[0]));
var result = new SaneArrayList();
foreach(string s in dirs) {
result.Add(context.runtime.NewText(s));
}
return context.runtime.NewList(result);
})));
obj.RegisterMethod(runtime.NewNativeMethod("Takes one string argument and returns true if it's the relative or absolute name of a directory, and false otherwise.",
new NativeMethod("directory?", DefaultArgumentsDefinition.builder()
.WithRequiredPositional("directoryName")
.Arguments,
(method, context, message, on, outer) => {
var args = new SaneArrayList();
outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
string name = Text.GetText(args[0]);
DirectoryInfo f = null;
if(IokeSystem.IsAbsoluteFileName(name)) {
f = new DirectoryInfo(name);
} else {
f = new DirectoryInfo(Path.Combine(context.runtime.CurrentWorkingDirectory, name));
}
return f.Exists ? context.runtime.True : context.runtime.False;
})));
obj.RegisterMethod(runtime.NewNativeMethod("Takes one string argument that should be a file name, and returns a text of the contents of this file.",
new NativeMethod("readFully", DefaultArgumentsDefinition.builder()
.WithRequiredPositional("fileName")
.Arguments,
(method, context, message, on, outer) => {
var args = new SaneArrayList();
outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
string name = Text.GetText(args[0]);
FileInfo f = null;
if(IokeSystem.IsAbsoluteFileName(name)) {
f = new FileInfo(name);
} else {
f = new FileInfo(Path.Combine(context.runtime.CurrentWorkingDirectory, name));
}
return context.runtime.NewText(File.ReadAllText(f.FullName));
})));
obj.RegisterMethod(runtime.NewNativeMethod("Takes one string argument and returns true if it's the relative or absolute name of a file, and false otherwise.",
new NativeMethod("file?", DefaultArgumentsDefinition.builder()
.WithRequiredPositional("fileName")
.Arguments,
(method, context, message, on, outer) => {
var args = new SaneArrayList();
outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
string name = Text.GetText(args[0]);
FileInfo f = null;
if(IokeSystem.IsAbsoluteFileName(name)) {
f = new FileInfo(name);
} else {
f = new FileInfo(Path.Combine(context.runtime.CurrentWorkingDirectory, name));
}
return f.Exists ? context.runtime.True : context.runtime.False;
})));
obj.RegisterMethod(runtime.NewNativeMethod("Takes one string argument and returns true if it's the relative or absolute name of something that exists.",
new NativeMethod("exists?", DefaultArgumentsDefinition.builder()
.WithRequiredPositional("entryName")
.Arguments,
(method, context, message, on, outer) => {
var args = new SaneArrayList();
outer.ArgumentsDefinition.GetEvaluatedArguments(context, message, on, args, new SaneDictionary<string, object>());
string name = Text.GetText(args[0]);
string nx = null;
if(IokeSystem.IsAbsoluteFileName(name)) {
nx = name;
} else {
nx = Path.Combine(context.runtime.CurrentWorkingDirectory, name);
}
return (new FileInfo(nx).Exists || new DirectoryInfo(nx).Exists) ? context.runtime.True : context.runtime.False;
//.........这里部分代码省略.........