Adds tostring and type functions
This commit is contained in:
parent
194e7236c4
commit
2dc59c5f8b
|
@ -46,7 +46,7 @@ namespace Upsilon.BaseTypes
|
|||
while (baseEnumerator.MoveNext())
|
||||
{
|
||||
var key = baseEnumerator.Current;
|
||||
if (key.Type == Type.Nil)
|
||||
if (key == null || key.Type == Type.Nil)
|
||||
break;
|
||||
var value = BaseIterator.GetValueFromIndex(key);
|
||||
if (value.Type == Type.Nil)
|
||||
|
|
|
@ -37,7 +37,6 @@ namespace Upsilon.StandardLibraries
|
|||
return new PairsScriptIterator(table);
|
||||
}
|
||||
|
||||
|
||||
[StandardLibraryScriptFunction("tonumber")]
|
||||
public ScriptNumber ToNumber(ScriptString obj)
|
||||
{
|
||||
|
@ -51,5 +50,18 @@ namespace Upsilon.StandardLibraries
|
|||
return new ScriptNumberLong(long.Parse(str));
|
||||
}
|
||||
}
|
||||
|
||||
[StandardLibraryScriptFunction("tostring")]
|
||||
public ScriptString ToString(ScriptType obj)
|
||||
{
|
||||
return new ScriptString(obj.ToString());
|
||||
}
|
||||
|
||||
[StandardLibraryScriptFunction("type")]
|
||||
public ScriptString Type(ScriptType obj)
|
||||
{
|
||||
return new ScriptString(obj.Type.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -73,5 +73,32 @@ return value
|
|||
Assert.Empty(script.Diagnostics.Messages);
|
||||
Assert.Equal(284, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToStringTest()
|
||||
{
|
||||
const string input = @"
|
||||
return tostring(100)
|
||||
";
|
||||
var script = new Script(input, BoundScope, StaticScope);
|
||||
Assert.Empty(script.Diagnostics.Messages);
|
||||
var result = script.Evaluate<string>();
|
||||
Assert.Empty(script.Diagnostics.Messages);
|
||||
Assert.Equal("100", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TypeTest()
|
||||
{
|
||||
const string input = @"
|
||||
return type(100)
|
||||
";
|
||||
var script = new Script(input, BoundScope, StaticScope);
|
||||
Assert.Empty(script.Diagnostics.Messages);
|
||||
var result = script.Evaluate<string>();
|
||||
Assert.Empty(script.Diagnostics.Messages);
|
||||
Assert.Equal("Number", result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue