本文整理汇总了C#中ScriptExecutionContext.GetScript方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptExecutionContext.GetScript方法的具体用法?C# ScriptExecutionContext.GetScript怎么用?C# ScriptExecutionContext.GetScript使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScriptExecutionContext
的用法示例。
在下文中一共展示了ScriptExecutionContext.GetScript方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: __index_callback
private static DynValue __index_callback(ScriptExecutionContext executionContext, CallbackArguments args)
{
string name = args[1].CastToString();
if (name == "stdin")
return GetStandardFile(executionContext.GetScript(), StandardFileType.StdIn);
else if (name == "stdout")
return GetStandardFile(executionContext.GetScript(), StandardFileType.StdOut);
else if (name == "stderr")
return GetStandardFile(executionContext.GetScript(), StandardFileType.StdErr);
else
return DynValue.Nil;
}
示例2: GetDefaultFile
static FileUserDataBase GetDefaultFile(ScriptExecutionContext executionContext, StandardFileType file)
{
Table R = executionContext.GetScript().Registry;
DynValue ff = R.Get("853BEAAF298648839E2C99D005E1DF94_" + file.ToString());
if (ff.IsNil())
{
ff = GetStandardFile(executionContext.GetScript(), file);
}
return ff.CheckUserDataType<FileUserDataBase>("getdefaultfile(" + file.ToString() + ")");
}
示例3: eval
public static DynValue eval(ScriptExecutionContext executionContext, CallbackArguments args)
{
try
{
if (args[0].Type == DataType.UserData)
{
UserData ud = args[0].UserData;
if (ud.Object is DynamicExprWrapper)
{
return ((DynamicExprWrapper)ud.Object).Expr.Evaluate(executionContext);
}
else
{
throw ScriptRuntimeException.BadArgument(0, "dynamic.eval", "A userdata was passed, but was not a previously prepared expression.");
}
}
else
{
DynValue vs = args.AsType(0, "dynamic.eval", DataType.String, false);
DynamicExpression expr = executionContext.GetScript().CreateDynamicExpression(vs.String);
return expr.Evaluate(executionContext);
}
}
catch (SyntaxErrorException ex)
{
throw new ScriptRuntimeException(ex);
}
}
示例4: create
public static DynValue create(ScriptExecutionContext executionContext, CallbackArguments args)
{
if (args[0].Type != DataType.Function && args[0].Type != DataType.ClrFunction)
args.AsType(0, "create", DataType.Function); // this throws
return executionContext.GetScript().CreateCoroutine(args[0]);
}
示例5: debug
public static DynValue debug(ScriptExecutionContext executionContext, CallbackArguments args)
{
var script = executionContext.GetScript();
if (script.Options.DebugInput == null)
throw new ScriptRuntimeException("debug.debug not supported on this platform/configuration");
var interpreter = new ReplInterpreter(script)
{
HandleDynamicExprs = false,
HandleClassicExprsSyntax = true
};
while (true)
{
var s = script.Options.DebugInput(interpreter.ClassicPrompt + " ");
try
{
var result = interpreter.Evaluate(s);
if (result != null && result.Type != DataType.Void)
script.Options.DebugPrint(string.Format("{0}", result));
}
catch (InterpreterException ex)
{
script.Options.DebugPrint(string.Format("{0}", ex.DecoratedMessage ?? ex.Message));
}
catch (Exception ex)
{
script.Options.DebugPrint(string.Format("{0}", ex.Message));
}
}
}
示例6: load_impl
public static DynValue load_impl(ScriptExecutionContext executionContext, CallbackArguments args, Table defaultEnv)
{
try
{
Script S = executionContext.GetScript();
DynValue ld = args[0];
string script = "";
if (ld.Type == DataType.Function)
{
while (true)
{
DynValue ret = executionContext.GetScript().Call(ld);
if (ret.Type == DataType.String && ret.String.Length > 0)
script += ret.String;
else if (ret.IsNil())
break;
else
return DynValue.NewTuple(DynValue.Nil, DynValue.NewString("reader function must return a string"));
}
}
else if (ld.Type == DataType.String)
{
script = ld.String;
}
else
{
args.AsType(0, "load", DataType.Function, false);
}
DynValue source = args.AsType(1, "load", DataType.String, true);
DynValue env = args.AsType(3, "load", DataType.Table, true);
DynValue fn = S.LoadString(script,
!env.IsNil() ? env.Table : defaultEnv,
!source.IsNil() ? source.String : "=(load)");
return fn;
}
catch (SyntaxErrorException ex)
{
return DynValue.NewTuple(DynValue.Nil, DynValue.NewString(ex.DecoratedMessage ?? ex.Message));
}
}
示例7: getmetatable
public static DynValue getmetatable(ScriptExecutionContext executionContext, CallbackArguments args)
{
var v = args[0];
var S = executionContext.GetScript();
if (v.Type.CanHaveTypeMetatables())
return DynValue.NewTable(S.GetTypeMetatable(v.Type));
if (v.Type == DataType.Table)
return DynValue.NewTable(v.Table.MetaTable);
return DynValue.Nil;
}
示例8: pack
public static DynValue pack(ScriptExecutionContext executionContext, CallbackArguments args)
{
var t = new Table(executionContext.GetScript());
var v = DynValue.NewTable(t);
for (var i = 0; i < args.Count; i++)
t.Set(i + 1, args[i]);
t.Set("n", DynValue.NewNumber(args.Count));
return v;
}
示例9: prepare
public static DynValue prepare(ScriptExecutionContext executionContext, CallbackArguments args)
{
try
{
DynValue vs = args.AsType(0, "dynamic.prepare", DataType.String, false);
DynamicExpression expr = executionContext.GetScript().CreateDynamicExpression(vs.String);
return UserData.Create(new DynamicExprWrapper() { Expr = expr });
}
catch (SyntaxErrorException ex)
{
throw new ScriptRuntimeException(ex);
}
}
示例10: parse
public static DynValue parse(ScriptExecutionContext executionContext, CallbackArguments args)
{
try
{
DynValue vs = args.AsType(0, "parse", DataType.String, false);
Table t = JsonTableConverter.JsonToTable(vs.String, executionContext.GetScript());
return DynValue.NewTable(t);
}
catch (SyntaxErrorException ex)
{
throw new ScriptRuntimeException(ex);
}
}
示例11: lines
public DynValue lines(ScriptExecutionContext executionContext, CallbackArguments args)
{
var readLines = new List<DynValue>();
DynValue readValue = null;
do
{
readValue = read(executionContext, args);
readLines.Add(readValue);
} while (readValue.IsNotNil());
return DynValue.FromObject(executionContext.GetScript(), readLines.Select(s => s));
}
示例12: dump
public static DynValue dump(ScriptExecutionContext executionContext, CallbackArguments args)
{
var fn = args.AsType(0, "dump", DataType.Function, false);
try
{
byte[] bytes;
using (var ms = new MemoryStream())
{
executionContext.GetScript().Dump(fn, ms);
ms.Seek(0, SeekOrigin.Begin);
bytes = ms.ToArray();
}
var base64 = Convert.ToBase64String(bytes);
return DynValue.NewString(BASE64_DUMP_HEADER + base64);
}
catch (Exception ex)
{
throw new ScriptRuntimeException(ex.Message);
}
}
示例13: getmetatable
public static DynValue getmetatable(ScriptExecutionContext executionContext, CallbackArguments args)
{
var obj = args[0];
Table meta = null;
if (obj.Type.CanHaveTypeMetatables())
{
meta = executionContext.GetScript().GetTypeMetatable(obj.Type);
}
if (obj.Type == DataType.Table)
{
meta = obj.Table.MetaTable;
}
if (meta == null)
return DynValue.Nil;
if (meta.RawGet("__metatable") != null)
return meta.Get("__metatable");
return DynValue.NewTable(meta);
}
示例14: __require_clr_impl
public static DynValue __require_clr_impl(ScriptExecutionContext executionContext, CallbackArguments args)
{
Script S = executionContext.GetScript();
DynValue v = args.AsType(0, "__require_clr_impl", DataType.String, false);
DynValue fn = S.RequireModule(v.String);
return fn; // tail call to dofile
}
示例15: Open
private static FileUserDataBase Open(ScriptExecutionContext executionContext, string filename, Encoding encoding, string mode)
{
return new FileUserData(executionContext.GetScript(), filename, encoding, mode);
}