Skip to content

Commit

Permalink
[dotnet] Add a couple of missing coercion ops to the runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Oct 18, 2010
1 parent 1b9b061 commit 30e4673
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions dotnet/runtime/Runtime/Ops.cs
Expand Up @@ -267,6 +267,34 @@ public static RakudoObject coerce_num_to_int(ThreadContext TC, RakudoObject Num,
return Ops.box_int(TC, (int)Value, TargetType);
}

/// <summary>
/// Coerces a string into an integer.
/// </summary>
/// <param name="TC"></param>
/// <param name="Str"></param>
/// <param name="TargetType"></param>
/// <returns></returns>
public static RakudoObject coerce_str_to_int(ThreadContext TC, RakudoObject Str, RakudoObject TargetType)
{
int Value = 0;
int.TryParse(Ops.unbox_str(TC, Str), out Value);
return Ops.box_int(TC, Value, TargetType);
}

/// <summary>
/// Coerces a string into an number.
/// </summary>
/// <param name="TC"></param>
/// <param name="Str"></param>
/// <param name="TargetType"></param>
/// <returns></returns>
public static RakudoObject coerce_str_to_num(ThreadContext TC, RakudoObject Str, RakudoObject TargetType)
{
double Value = 0;
double.TryParse(Ops.unbox_str(TC, Str), out Value);
return Ops.box_num(TC, Value, TargetType);
}

/// <summary>
/// Gets a lexical variable of the given name.
/// </summary>
Expand Down

0 comments on commit 30e4673

Please sign in to comment.