Skip to content

Commit

Permalink
Автоматическая регистрация битовых функций.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmpas committed Sep 30, 2017
1 parent 17c1cba commit 90d115c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 121 deletions.
3 changes: 0 additions & 3 deletions src/ScriptEngine.HostedScript/HostedScriptEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public HostedScriptEngine()

_env.InjectObject(_globalCtx, false);
_engine.Environment = _env;

_env.InjectObject(new GlobalBitFunctions(), asDynamicScope: false);

}

public void InitExternalLibraries(string systemLibrary, IEnumerable<string> searchDirs)
Expand Down
122 changes: 4 additions & 118 deletions src/ScriptEngine.HostedScript/Library/GlobalBitFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace ScriptEngine.HostedScript.Library
/// <summary>
/// Глобальный контекст. Побитовые операции с целыми числами.
/// </summary>
[GlobalContext(Category="Побитовые операции с целыми числами", ManualRegistration=true)]
public class GlobalBitFunctions : IAttachableContext
[GlobalContext(Category="Побитовые операции с целыми числами")]
public sealed class GlobalBitFunctions : GlobalContextBase<GlobalBitFunctions>
{

/// <summary>
Expand Down Expand Up @@ -152,123 +152,9 @@ public uint BitwiseShiftRight(uint value, int offset)
return value >> offset;
}

#region IAttachableContext Members

public void OnAttach(MachineInstance machine,
out IVariable[] variables,
out MethodInfo[] methods)
{
variables = new IVariable[0];
methods = GetMethods().ToArray();
}

public IEnumerable<MethodInfo> GetMethods()
{
var array = new MethodInfo[_methods.Count];
for (int i = 0; i < _methods.Count; i++)
{
array[i] = _methods.GetMethodInfo(i);
}
return array;
}

#endregion

#region IRuntimeContextInstance Members

public bool IsIndexed
{
get
{
return false;
}
}

public bool DynamicMethodSignatures
{
get
{
return false;
}
}

public IValue GetIndexedValue(IValue index)
{
throw new NotSupportedException();
}

public void SetIndexedValue(IValue index, IValue val)
{
throw new NotSupportedException();
}

public int FindProperty(string name)
{
return -1;
}

public bool IsPropReadable(int propNum)
{
throw new NotSupportedException();
}

public bool IsPropWritable(int propNum)
{
throw new NotSupportedException();
}

public IValue GetPropValue(int propNum)
{
throw new NotSupportedException();
}

public void SetPropValue(int propNum, IValue newVal)
{
throw new NotSupportedException();
}

public int GetPropCount()
{
return 0;
}

public string GetPropName(int index)
{
throw new NotSupportedException();
}

public int FindMethod(string name)
{
return _methods.FindMethod(name);
}

public MethodInfo GetMethodInfo(int methodNumber)
{
return _methods.GetMethodInfo(methodNumber);
}

public int GetMethodsCount()
{
return _methods.Count;
}

public void CallAsProcedure(int methodNumber, IValue[] arguments)
{
_methods.GetMethod(methodNumber)(this, arguments);
}

public void CallAsFunction(int methodNumber, IValue[] arguments, out IValue retValue)
{
retValue = _methods.GetMethod(methodNumber)(this, arguments);
}

#endregion

private static readonly ContextMethodsMapper<GlobalBitFunctions> _methods;

static GlobalBitFunctions()
public static IAttachableContext CreateInstance()
{
_methods = new ContextMethodsMapper<GlobalBitFunctions>();
return new GlobalBitFunctions();
}
}
}

0 comments on commit 90d115c

Please sign in to comment.