本文整理汇总了C#中System.Script类的典型用法代码示例。如果您正苦于以下问题:C# Script类的具体用法?C# Script怎么用?C# Script使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Script类属于System命名空间,在下文中一共展示了Script类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadChunk
internal static int LoadChunk(Script script, SourceCode source, ByteCode bytecode, Table globalContext)
{
ScriptLoadingContext lcontext = CreateLoadingContext(script, source);
try
{
Statement stat;
using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation))
stat = new ChunkStatement(lcontext, globalContext);
int beginIp = -1;
//var srcref = new SourceRef(source.SourceID);
using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Compilation))
using (bytecode.EnterSource(null))
{
bytecode.Emit_Nop(string.Format("Begin chunk {0}", source.Name));
beginIp = bytecode.GetJumpPointForLastInstruction();
stat.Compile(bytecode);
bytecode.Emit_Nop(string.Format("End chunk {0}", source.Name));
}
//Debug_DumpByteCode(bytecode, source.SourceID);
return beginIp;
}
catch (SyntaxErrorException ex)
{
ex.DecorateMessage(script);
throw;
}
}
示例2: GetSigOpCount
public void GetSigOpCount()
{
// Test CScript::GetSigOpCount()
Script s1 = new Script();
Assert.Equal(s1.GetSigOpCount(false), 0U);
Assert.Equal(s1.GetSigOpCount(true), 0U);
uint160 dummy = new uint160(0);
s1 = s1 + OpcodeType.OP_1 + dummy.ToBytes() + dummy.ToBytes() + OpcodeType.OP_2 + OpcodeType.OP_CHECKMULTISIG;
Assert.Equal(s1.GetSigOpCount(true), 2U);
s1 = s1 + OpcodeType.OP_IF + OpcodeType.OP_CHECKSIG + OpcodeType.OP_ENDIF;
Assert.Equal(s1.GetSigOpCount(true), 3U);
Assert.Equal(s1.GetSigOpCount(false), 21U);
Script p2sh = PayToScriptHashTemplate.Instance.GenerateScriptPubKey(s1);
Script scriptSig = PayToScriptHashTemplate.Instance.GenerateScriptSig(new[] { (Op)OpcodeType.OP_0 }, s1);
Assert.Equal(p2sh.GetSigOpCount(scriptSig), 3U);
PubKey[] keys = Enumerable.Range(0, 3).Select(_ => new Key(true).PubKey).ToArray();
Script s2 = PayToMultiSigTemplate.Instance.GenerateScriptPubKey(1, keys);
Assert.Equal(s2.GetSigOpCount(true), 3U);
Assert.Equal(s2.GetSigOpCount(false), 20U);
p2sh = PayToScriptHashTemplate.Instance.GenerateScriptPubKey(s2);
Assert.Equal(p2sh.GetSigOpCount(true), 0U);
Assert.Equal(p2sh.GetSigOpCount(false), 0U);
Script scriptSig2 = new Script();
scriptSig2 = scriptSig2 + OpcodeType.OP_1 + dummy.ToBytes() + dummy.ToBytes() + s2.ToBytes();
Assert.Equal(p2sh.GetSigOpCount(scriptSig2), 3U);
}
示例3: ReadScript
private bool ReadScript(Script script)
{
try
{
var data = TxNullDataTemplate.Instance.ExtractScriptPubKeyParameters(script);
if(data == null)
return false;
BitcoinStream stream = new BitcoinStream(data);
ushort marker = 0;
stream.ReadWrite(ref marker);
if(marker != Tag)
return false;
stream.ReadWrite(ref _Version);
if(_Version != 1)
return false;
ulong quantityCount = 0;
stream.ReadWriteAsVarInt(ref quantityCount);
Quantities = new ulong[quantityCount];
for(ulong i = 0 ; i < quantityCount ; i++)
{
Quantities[i] = ReadLEB128(stream);
if(Quantities[i] > MAX_QUANTITY)
return false;
}
stream.ReadWriteAsVarString(ref _Metadata);
return true;
}
catch(Exception)
{
return false;
}
}
示例4: Set
public override void Set(Script script, Scope scope, object obj, object value)
{
if (_isMethod)
{
throw new Exception("The left-hand side of an assignment must be a variable, property or indexer.");
}
else
{
Type t = obj.GetType();
PropertyInfo result = t.GetProperty(_name);
if (result != null)
{
if (!result.CanWrite)
{
throw new FieldAccessException("Cannot modify the value of " + _name + ", it is read-only.");
}
result.GetSetMethod().Invoke(obj, new[] {value});
}
else
{
FieldInfo[] fi = t.GetFields();
for (int i = 0; i < fi.Length; i++)
{
if (fi[i].Name == _name)
{
fi[i].SetValue(obj, value);
return;
}
}
}
}
}
示例5: Execute
public override object Execute(Script script, Scope scope, Token previousToken, object unknown)
{
if (unknown == null)
{
throw new NullReferenceException("obj cannot be null...");
}
if (unknown is object[])
{
// We are assuming that the tokens count is 1, and that it gives us a number.
if (_tokens.Count == 1)
{
// Evaluate.
object id = new Chunk(_tokens[0], script).Evaluate(scope);
if (id != null && id is Number)
{
return ((object[]) unknown)[((Number) id).GetValue<int>()];
}
else
{
throw new Exception("For a array of type object[], the key must be a number!");
}
}
throw new Exception(":O");
}
else
{
Type type = (unknown is Type) ? (Type) unknown : unknown.GetType();
return Invoke(script, scope, unknown, type, (type == typeof(String)) ? "Chars" : "Item",
_tokens, new List<string>());
}
}
示例6: Execute
public override object Execute(Script script, Scope scope, Token previousToken, object unknown)
{
if (unknown == null && previousToken != null)
{
// Cannot execute.
throw new NullReferenceException("obj cannot be null...");
}
else if (unknown == null && previousToken == null)
{
// Check our list of "functions".
if (scope.Functions.Contains(_name))
{
return scope.Functions.Invoke(script, scope, _name, _arguments);
}
else if (script.Engine != null && script.Engine.Functions.Contains(_name))
{
return script.Engine.Functions.Invoke(script, scope, _name, _arguments);
}
else
{
throw new Exception(String.Format("No function named {0}...", _name));
}
}
Type type = (unknown is Type) ? (Type) unknown : unknown.GetType();
return _isMethod
? Invoke(script, scope, unknown, type, _name, _arguments, _generics)
: FieldInvoke(unknown, _name, type);
}
示例7: Do
void Do(string code, Action<DynValue, RegCollMethods> asserts)
{
try
{
UserData.RegisterType<RegCollMethods>();
UserData.RegisterType<RegCollItem>();
UserData.RegisterType(typeof(IList<>));
Script s = new Script();
var obj = new RegCollMethods();
s.Globals["o"] = obj;
s.Globals["ctor"] = UserData.CreateStatic<RegCollItem>();
DynValue res = s.DoString(code);
asserts(res, obj);
}
catch (ScriptRuntimeException ex)
{
Debug.WriteLine(ex.DecoratedMessage);
throw;
}
finally
{
UserData.UnregisterType<RegCollMethods>();
UserData.UnregisterType<RegCollItem>();
UserData.UnregisterType<Array>();
UserData.UnregisterType(typeof(IList<>));
UserData.UnregisterType(typeof(IList<RegCollItem>));
UserData.UnregisterType(typeof(IList<int>));
//UserData.UnregisterType<IEnumerable>();
}
}
示例8: TailCallFromCLR
public void TailCallFromCLR()
{
string script = @"
function getResult(x)
return 156*x;
end
return clrtail(9)";
Script S = new Script();
S.Globals.Set("clrtail", DynValue.NewCallback((xc, a) =>
{
DynValue fn = S.Globals.Get("getResult");
DynValue k3 = DynValue.NewNumber(a[0].Number / 3);
return DynValue.NewTailCallReq(fn, k3);
}));
var res = S.DoString(script);
Assert.AreEqual(DataType.Number, res.Type);
Assert.AreEqual(468, res.Number);
}
示例9: LoadFunction
internal static int LoadFunction(Script script, SourceCode source, ByteCode bytecode, Table globalContext)
{
ScriptLoadingContext lcontext = CreateLoadingContext(script, source);
try
{
FunctionDefinitionExpression fnx;
using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation))
fnx = new FunctionDefinitionExpression(lcontext, globalContext);
int beginIp = -1;
//var srcref = new SourceRef(source.SourceID);
using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Compilation))
using (bytecode.EnterSource(null))
{
bytecode.Emit_Nop(string.Format("Begin function {0}", source.Name));
beginIp = fnx.CompileBody(bytecode, source.Name);
bytecode.Emit_Nop(string.Format("End function {0}", source.Name));
}
//Debug_DumpByteCode(bytecode, source.SourceID);
return beginIp;
}
catch (SyntaxErrorException ex)
{
ex.DecorateMessage(script);
throw;
}
}
示例10: CombineScriptSig
public override Script CombineScriptSig(Script scriptPubKey, Script a, Script b)
{
var para = PayToMultiSigTemplate.Instance.ExtractScriptPubKeyParameters(scriptPubKey);
// Combine all the signatures we've got:
var aSigs = PayToMultiSigTemplate.Instance.ExtractScriptSigParameters(a);
if(aSigs == null)
return b;
var bSigs = PayToMultiSigTemplate.Instance.ExtractScriptSigParameters(b);
if(bSigs == null)
return a;
int pubkeyCount = 0;
TransactionSignature[] sigs = new TransactionSignature[para.PubKeys.Length];
for(int i = 0 ; i < para.PubKeys.Length ; i++)
{
var aSig = i < aSigs.Length ? aSigs[i] : null;
var bSig = i < bSigs.Length ? bSigs[i] : null;
var sig = aSig ?? bSig;
if(sig != null)
{
sigs[pubkeyCount] = sig;
pubkeyCount++;
}
if(pubkeyCount == para.SignatureCount)
break;
}
if(pubkeyCount == para.SignatureCount)
sigs = sigs.Where(s => s != null && s != TransactionSignature.Empty).ToArray();
return PayToMultiSigTemplate.Instance.GenerateScriptSig(sigs);
}
示例11: Load
public static void Load(Script script)
{
ScriptTable Table = script.CreateTable();
Table.SetValue("encode", script.CreateFunction(new encode()));
Table.SetValue("decode", script.CreateFunction(new decode(script)));
script.SetObjectInternal("json", Table);
}
示例12: LoadScript
//////////////////////////////////////////////////////////////////////////
public void LoadScript(DebugClient Client, Script Script)
{
_Client = Client;
_Script = Script;
this.BeginUpdate();
this.Items.Clear();
SourceValid = false;
if (_Client != null && _Script != null)
{
string FullPath = _Client.Server.ResolveFilename(_Script.Filename);
ReadLines(FullPath);
SelectLine(Script.Line, true);
}
foreach (ColumnHeader Col in this.Columns)
{
Col.Width = -1;
}
this.EndUpdate();
RefreshBreakpoints();
}
示例13: Build
public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
{
while ((++sourceCode).SpecialChar)
{
}
if (sourceCode.Peek() != '{')
{
sourceCode.Throw(String.Format("Error parsing a 'do' statement, expected a '{' but got '{0}' instead.",
sourceCode.Peek()));
}
List<List<List<Token>>> code = engine.BuildLongTokens(ref sourceCode, ref script, new[] {'}'});
if (!sourceCode.SeekToNext("while"))
{
sourceCode.Throw("Error parsing a 'do' statement, was expecting a 'while' after the { } block.");
}
if (!sourceCode.SeekToNext('('))
{
sourceCode.Throw("Error parsing a 'do' statement, was expecting a '(' after 'while'.");
}
List<List<Token>> exitCondition = engine.BuildTokensAdvanced(ref sourceCode, ref script, new[] {')'});
return new DoWhileToken(code, exitCondition);
}
示例14: TableAddWithMetatable
public void TableAddWithMetatable()
{
string script = @"
v1 = { 'aaaa' }
v2 = { 'aaaaaa' }
meta = { }
function meta.__add(t1, t2)
local o1 = #t1[1];
local o2 = #t2[1];
return o1 * o2;
end
setmetatable(v1, meta);
return(v1 + v2);";
var S = new Script();
Table globalCtx = S.Globals;
globalCtx.RegisterModuleType<TableIteratorsModule>();
globalCtx.RegisterModuleType<MetaTableModule>();
DynValue res = S.DoString(script);
Assert.AreEqual(DataType.Number, res.Type);
Assert.AreEqual(24, res.Number);
}
示例15: Build
public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
{
// while (condition) { /* Code */ }
sourceCode += 4; // The +1 comes from below.
while ((++sourceCode).SpecialChar)
{
}
if (sourceCode.CurrentCode != '(')
{
sourceCode.Throw("Error parsing a 'while' statement, was epexting a '(' after 'while'.");
}
List<List<Token>> exitCondition = engine.BuildTokensAdvanced(ref sourceCode, ref script, new[] {')'});
if (!sourceCode.SeekToNext('{'))
{
sourceCode.Throw(String.Format("Unexpected char: '{0}'", sourceCode.CurrentCode));
}
List<List<List<Token>>> code = engine.BuildLongTokens(ref sourceCode, ref script, new[] {'}'});
return new WhileLoopToken(exitCondition, code);
}