本文整理汇总了C#中Iodine.Runtime.VirtualMachine.RaiseException方法的典型用法代码示例。如果您正苦于以下问题:C# VirtualMachine.RaiseException方法的具体用法?C# VirtualMachine.RaiseException怎么用?C# VirtualMachine.RaiseException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Iodine.Runtime.VirtualMachine
的用法示例。
在下文中一共展示了VirtualMachine.RaiseException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: pow
private IodineObject pow (VirtualMachine vm, IodineObject self, IodineObject[] args)
{
if (args.Length <= 1) {
vm.RaiseException (new IodineArgumentException (2));
return null;
}
double a1 = 0;
double a2 = 0;
if (args [0] is IodineInteger) {
a1 = (double)((IodineInteger)args [0]).Value;
} else if (args [0] is IodineFloat) {
a1 = ((IodineFloat)args [0]).Value;
} else {
vm.RaiseException (new IodineTypeException ("Float"));
return null;
}
if (args [1] is IodineInteger) {
a2 = (double)((IodineInteger)args [1]).Value;
} else if (args [1] is IodineFloat) {
a2 = ((IodineFloat)args [1]).Value;
} else {
vm.RaiseException (new IodineTypeException ("Float"));
return null;
}
return new IodineFloat (Math.Pow (a1, a2));
}
示例2: Invoke
public override IodineObject Invoke (VirtualMachine vm, IodineObject[] args)
{
if (args.Length <= 0) {
vm.RaiseException (new IodineArgumentException (1));
}
if (args [0] is IodineFloat) {
IodineFloat fp = args [0] as IodineFloat;
return new IodineInteger ((long)fp.Value);
}
long value;
NumberStyles style = NumberStyles.AllowLeadingSign;
if (args.Length > 1) {
IodineInteger basen = args [1] as IodineInteger;
switch (basen.Value) {
case 16:
style = NumberStyles.HexNumber;
break;
}
}
if (!Int64.TryParse (args [0].ToString (), style, null, out value)) {
vm.RaiseException (new IodineTypeCastException ("Int"));
return null;
} else {
return new IodineInteger (value);
}
}
示例3: listFiles
private IodineObject listFiles (VirtualMachine vm, IodineObject self, IodineObject[] args)
{
if (args.Length <= 0) {
vm.RaiseException (new IodineArgumentException (1));
return null;
}
if (!(args [0] is IodineString)) {
vm.RaiseException (new IodineTypeException ("Str"));
return null;
}
if (!Directory.Exists (args [0].ToString ())) {
vm.RaiseException (new IodineIOException ("Directory '" + args [0].ToString () +
"' does not exist!"));
return null;
}
IodineList ret = new IodineList (new IodineObject[]{ });
foreach (string dir in Directory.GetFiles (args[0].ToString ())) {
ret.Add (new IodineString (dir));
}
return ret;
}
示例4: sha256
private IodineObject sha256 (VirtualMachine vm, IodineObject self, IodineObject[] args)
{
if (args.Length <= 0) {
vm.RaiseException (new IodineArgumentException (1));
return null;
}
byte[] bytes = new byte[]{};
byte[] hash = null;
SHA256Managed hashstring = new SHA256Managed();
if (args[0] is IodineString) {
bytes = System.Text.Encoding.UTF8.GetBytes (args[0].ToString ());
hash = hashstring.ComputeHash(bytes);
} else if (args[0] is IodineByteArray) {
bytes = ((IodineByteArray)args[0]).Array;
hash = hashstring.ComputeHash(bytes);
} else if (args[0] is IodineStream) {
hash = hashstring.ComputeHash(((IodineStream)args[0]).File);
} else {
vm.RaiseException (new IodineTypeException ("Str"));
return null;
}
return new IodineByteArray (hash);
}
示例5: randInt
private IodineObject randInt (VirtualMachine vm, IodineObject self, IodineObject[] args)
{
if (args.Length <= 0) {
return new IodineInteger (rgn.Next (Int32.MinValue, Int32.MaxValue));
} else {
int start = 0;
int end = 0;
if (args.Length <= 1) {
IodineInteger integer = args [0] as IodineInteger;
if (integer == null) {
vm.RaiseException (new IodineTypeException ("Int"));
return null;
}
end = (int)integer.Value;
} else {
IodineInteger startInteger = args [0] as IodineInteger;
IodineInteger endInteger = args [1] as IodineInteger;
if (startInteger == null || endInteger == null) {
vm.RaiseException (new IodineTypeException ("Int"));
return null;
}
start = (int)startInteger.Value;
end = (int)endInteger.Value;
}
return new IodineInteger (rgn.Next (start, end));
}
}
示例6: pack
private IodineObject pack (VirtualMachine vm, IodineObject self, IodineObject[] args)
{
if (args.Length < 2) {
vm.RaiseException (new IodineArgumentException (2));
return null;
}
IodineString format = args [0] as IodineString;
IodineTuple tuple = args [1] as IodineTuple;
if (format == null) {
vm.RaiseException (new IodineTypeException ("Str"));
return null;
}
if (tuple == null) {
vm.RaiseException (new IodineTypeException ("Tuple"));
return null;
}
int nextObj = 0;
using (MemoryStream ms = new MemoryStream ())
using (BinaryWriter bw = new BinaryWriter (ms)) {
int i = 0;
while (i < format.Value.Length) {
int arg = 1;
if (i < format.Value.Length && char.IsDigit (format.Value [i])) {
StringBuilder accum = new StringBuilder ();
do {
accum.Append (format.Value [i++]);
} while (i < format.Value.Length && char.IsDigit (format.Value [i]));
arg = Int32.Parse (accum.ToString ());
}
if (i < format.Value.Length) {
char specifier = format.Value [i++];
if (specifier == 'x') {
for (int j = 0; j < arg; j++) {
bw.Write ((byte)0);
}
} else {
if (nextObj > tuple.Objects.Length) {
vm.RaiseException (new IodineException ("Invalid format"));
return null;
}
IodineObject obj = tuple.Objects [nextObj++];
if (!packObj (vm, bw, specifier, arg, obj)) {
vm.RaiseException (new IodineException ("Invalid format"));
return null;
}
}
}
}
return new IodineBytes (ms.ToArray ());
}
}
示例7: wrapSsl
private IodineObject wrapSsl (VirtualMachine vm, IodineObject self, IodineObject[] args)
{
if (args.Length <= 0) {
vm.RaiseException (new IodineArgumentException (1));
return null;
}
IodineStream rawStream = args [0] as IodineStream;
if (rawStream == null) {
vm.RaiseException (new IodineTypeException ("Stream"));
return null;
}
SslStream stream = new SslStream (rawStream.File, false, ValidateServerCertificate);
stream.AuthenticateAsClient ("int0x10.com");
return new IodineStream (stream, true, true);
}
示例8: isMatch
private IodineObject isMatch (VirtualMachine vm, IodineObject self, IodineObject[] args)
{
if (args.Length <= 0) {
vm.RaiseException (new IodineArgumentException (1));
return null;
}
IodineString expr = args [0] as IodineString;
if (expr == null) {
vm.RaiseException (new IodineTypeException ("Str"));
return null;
}
return IodineBool.Create (Value.IsMatch (expr.ToString ()));
}
示例9: getEnv
private IodineObject getEnv(VirtualMachine vm, IodineObject self, IodineObject[] args)
{
if (args.Length <= 0) {
vm.RaiseException (new IodineArgumentException (1));
}
IodineString str = args [0] as IodineString;
if (str == null) {
vm.RaiseException (new IodineTypeException ("Str"));
return null;
}
if (Environment.GetEnvironmentVariable (str.Value) != null)
return new IodineString (Environment.GetEnvironmentVariable (str.Value));
else
return null;
}
示例10: write
private IodineObject write (VirtualMachine vm, IodineObject self, IodineObject[] args)
{
if (Closed) {
vm.RaiseException (new IodineIOException ("Stream has been closed!"));
return null;
}
if (!CanWrite) {
vm.RaiseException (new IodineIOException ("Can not write to stream!"));
return null;
}
foreach (IodineObject obj in args) {
if (obj is IodineString) {
write (obj.ToString ());
} else if (obj is IodineBytes) {
IodineBytes arr = obj as IodineBytes;
File.Write (arr.Value, 0, arr.Value.Length);
} else if (obj is IodineInteger) {
IodineInteger intVal = obj as IodineInteger;
write ((byte)intVal.Value);
} else if (obj is IodineByteArray) {
IodineByteArray arr = obj as IodineByteArray;
File.Write (arr.Array, 0, arr.Array.Length);
} else {
vm.RaiseException (new IodineTypeException (""));
}
}
return null;
}
示例11: Invoke
public override IodineObject Invoke (VirtualMachine vm, IodineObject[] args)
{
if (args.Length <= 0) {
vm.RaiseException (new IodineArgumentException (1));
}
return IodineBool.Create (Boolean.Parse (args [0].ToString ()));
}
示例12: Invoke
public override IodineObject Invoke (VirtualMachine vm, IodineObject[] args)
{
if (args.Length <= 0) {
vm.RaiseException (new IodineArgumentException (1));
}
return new IodineBytes (args [0].ToString ());
}
示例13: exit
private IodineObject exit(VirtualMachine vm, IodineObject self, IodineObject[] args)
{
if (args.Length <= 0) {
vm.RaiseException (new IodineArgumentException (1));
return null;
}
IodineInteger code = args [0] as IodineInteger;
if (code == null) {
vm.RaiseException (new IodineTypeException ("Int"));
return null;
}
Environment.Exit ((int)code.Value);
return null;
}
示例14: GetIndex
public override IodineObject GetIndex (VirtualMachine vm, IodineObject key)
{
IodineInteger index = key as IodineInteger;
if (index.Value < Objects.Length)
return Objects [(int)index.Value];
vm.RaiseException (new IodineIndexException ());
return null;
}
示例15: sleep
private IodineObject sleep(VirtualMachine vm, IodineObject self, IodineObject[] args)
{
if (args.Length <= 0) {
vm.RaiseException (new IodineArgumentException (1));
}
IodineInteger time = args [0] as IodineInteger;
System.Threading.Thread.Sleep ((int)time.Value);
return null;
}