Adds comments to basic library functions
This commit is contained in:
parent
1f1b8c621e
commit
1243492453
|
@ -11,7 +11,8 @@ namespace Upsilon.StandardLibraries
|
|||
{
|
||||
internal class BasicFunctions : ScriptLibrary
|
||||
{
|
||||
[StandardLibraryScriptFunction("assert")]
|
||||
[StandardLibraryScriptFunction("assert", "Asserts that the parameter passed is true. Throws an exception if it is not true. " +
|
||||
"Can take a message to show in the exception, otherwise throws with message \"assertion failed!\"")]
|
||||
public void Assert(ScriptBoolean boolean, ScriptString message = null)
|
||||
{
|
||||
if (!boolean)
|
||||
|
@ -20,32 +21,32 @@ namespace Upsilon.StandardLibraries
|
|||
}
|
||||
}
|
||||
|
||||
[StandardLibraryScriptFunction("error")]
|
||||
[StandardLibraryScriptFunction("error", "Throw an exception with given error message")]
|
||||
public void Error(ScriptString message)
|
||||
{
|
||||
throw new Exception(message.Value);
|
||||
}
|
||||
|
||||
[StandardLibraryScriptFunction("ipairs")]
|
||||
[StandardLibraryScriptFunction("ipairs", "Iterates over an iterable variable, like a table, until it encounters a nil value.")]
|
||||
public IIterable UpTillNullPairs(IIterable table)
|
||||
{
|
||||
return new UpTillNullPairsScriptIterator(table);
|
||||
}
|
||||
|
||||
[StandardLibraryScriptFunction("pairs")]
|
||||
[StandardLibraryScriptFunction("pairs", "Iterates over an iterable variable, like a table, skipping all nil values.")]
|
||||
public IIterable Pairs(IIterable table)
|
||||
{
|
||||
return new PairsScriptIterator(table);
|
||||
}
|
||||
|
||||
[StandardLibraryScriptFunction("require", true)]
|
||||
[StandardLibraryScriptFunction("require", "Loads a module from the module path, using the given script loader.", true)]
|
||||
public void Require(Script script, string file)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
[StandardLibraryScriptFunction("tonumber")]
|
||||
[StandardLibraryScriptFunction("tonumber", "Parses a string to a number.")]
|
||||
public ScriptNumber ToNumber(ScriptString obj)
|
||||
{
|
||||
var str = obj.Value;
|
||||
|
@ -59,13 +60,13 @@ namespace Upsilon.StandardLibraries
|
|||
}
|
||||
}
|
||||
|
||||
[StandardLibraryScriptFunction("tostring")]
|
||||
[StandardLibraryScriptFunction("tostring", "Returns the string value of the given object.")]
|
||||
public ScriptString ToString(ScriptType obj)
|
||||
{
|
||||
return new ScriptString(obj.ToString());
|
||||
}
|
||||
|
||||
[StandardLibraryScriptFunction("type")]
|
||||
[StandardLibraryScriptFunction("type", "Returns the type of the given object as a string.")]
|
||||
public ScriptString Type(ScriptType obj)
|
||||
{
|
||||
return new ScriptString(obj.Type.ToString());
|
||||
|
|
|
@ -8,17 +8,20 @@ namespace Upsilon.StandardLibraries
|
|||
{
|
||||
internal abstract class ScriptLibrary
|
||||
{
|
||||
public Dictionary<string, ScriptMethodInfoFunction> LoadMethods()
|
||||
public Dictionary<string, LoadedStandardFunction> LoadMethods()
|
||||
{
|
||||
var dictionary = new Dictionary<string, ScriptMethodInfoFunction>();
|
||||
var dictionary = new Dictionary<string, LoadedStandardFunction>();
|
||||
var methods = GetType().GetMethods();
|
||||
foreach (var methodInfo in methods)
|
||||
{
|
||||
var attr = methodInfo.GetCustomAttribute<StandardLibraryScriptFunctionAttribute>();
|
||||
if (attr != null)
|
||||
{
|
||||
dictionary.Add(attr.Name,
|
||||
new ScriptMethodInfoFunction(new UserDataMethod(methodInfo), this, true));
|
||||
dictionary.Add(attr.Name, new LoadedStandardFunction()
|
||||
{
|
||||
MethodInfoFunction = new ScriptMethodInfoFunction(new UserDataMethod(methodInfo), this, true),
|
||||
CommentValue = attr.Comment
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,4 +29,10 @@ namespace Upsilon.StandardLibraries
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
internal class LoadedStandardFunction
|
||||
{
|
||||
public ScriptMethodInfoFunction MethodInfoFunction { get; set; }
|
||||
public string CommentValue { get; set; }
|
||||
}
|
||||
}
|
|
@ -5,13 +5,15 @@ namespace Upsilon.StandardLibraries
|
|||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
|
||||
public class StandardLibraryScriptFunctionAttribute : Attribute
|
||||
{
|
||||
public StandardLibraryScriptFunctionAttribute(string name, bool passScriptReference = false)
|
||||
public StandardLibraryScriptFunctionAttribute(string name, string comment = null, bool passScriptReference = false)
|
||||
{
|
||||
Name = name;
|
||||
Comment = comment;
|
||||
PassScriptReference = passScriptReference;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public string Comment { get; }
|
||||
public bool PassScriptReference { get; }
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
|
@ -47,9 +48,14 @@ namespace Upsilon.StandardLibraries
|
|||
var boundFuncs = new Dictionary<string, VariableSymbol>();
|
||||
foreach (var func in basicFunctions)
|
||||
{
|
||||
funcs.Add(func.Key, func.Value);
|
||||
boundFuncs.Add(func.Key, new FunctionVariableSymbol(func.Key, true, ImmutableArray<VariableSymbol>.Empty,
|
||||
func.Value.ReturnType.GetScriptType(), true){IsBound = true});
|
||||
funcs.Add(func.Key, func.Value.MethodInfoFunction);
|
||||
var functionSymbol = new FunctionVariableSymbol(func.Key, true, ImmutableArray<VariableSymbol>.Empty,
|
||||
func.Value.MethodInfoFunction.ReturnType.GetScriptType(), true)
|
||||
{
|
||||
IsBound = true,
|
||||
CommentValue = func.Value.CommentValue?.Split('\n')
|
||||
};
|
||||
boundFuncs.Add(func.Key, functionSymbol);
|
||||
}
|
||||
var scope = new EvaluationScope(funcs);
|
||||
var boundScope = new BoundScope(boundFuncs, null);
|
||||
|
|
Loading…
Reference in New Issue