public static DynValue type(ScriptExecutionContext executionContext, CallbackArguments args) { if (args.Count < 1) throw ScriptRuntimeException.BadArgumentValueExpected(0, "type"); DynValue v = args[0]; return DynValue.NewString(v.Type.ToLuaTypeString()); }
public static DynValue execute(ScriptExecutionContext executionContext, CallbackArguments args) { DynValue v = args.AsType(0, "execute", DataType.String, true); if (v.IsNil()) { return DynValue.NewBoolean(true); } else { try { int exitCode = Script.GlobalOptions.Platform.OS_Execute(v.String); return DynValue.NewTuple( DynValue.Nil, DynValue.NewString("exit"), DynValue.NewNumber(exitCode)); } catch (Exception) { // +++ bad to swallow.. return DynValue.Nil; } } }
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)); } } }
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]); }
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); } }
public static DynValue sort(ScriptExecutionContext executionContext, CallbackArguments args) { var vlist = args.AsType(0, "sort", DataType.Table, false); var lt = args[1]; if (lt.Type != DataType.Function && lt.Type != DataType.ClrFunction && lt.IsNotNil()) args.AsType(1, "sort", DataType.Function, true); // this throws var end = GetTableLength(executionContext, vlist); var values = new List<DynValue>(); for (var i = 1; i <= end; i++) values.Add(vlist.Table.Get(i)); try { values.Sort((a, b) => SortComparer(executionContext, a, b, lt)); } catch (InvalidOperationException ex) { if (ex.InnerException is ScriptRuntimeException) throw ex.InnerException; } for (var i = 0; i < values.Count; i++) { vlist.Table.Set(i + 1, values[i]); } return vlist; }
private static DynValue SetErrorHandlerStrategy(string funcName, ScriptExecutionContext executionContext, CallbackArguments args, DynValue handlerBeforeUnwind) { var v = args[0]; var a = new DynValue[args.Count - 1]; for (var i = 1; i < args.Count; i++) a[i - 1] = args[i]; if (args[0].Type == DataType.ClrFunction) { try { var ret = args[0].Callback.Invoke(executionContext, a); if (ret.Type == DataType.TailCallRequest) { if (ret.TailCallData.Continuation != null || ret.TailCallData.ErrorHandler != null) throw new ScriptRuntimeException( "the function passed to {0} cannot be called directly by {0}. wrap in a script function instead.", funcName); return DynValue.NewTailCallReq(new TailCallData { Args = ret.TailCallData.Args, Function = ret.TailCallData.Function, Continuation = new CallbackFunction(pcall_continuation, funcName), ErrorHandler = new CallbackFunction(pcall_onerror, funcName), ErrorHandlerBeforeUnwind = handlerBeforeUnwind }); } if (ret.Type == DataType.YieldRequest) { throw new ScriptRuntimeException( "the function passed to {0} cannot be called directly by {0}. wrap in a script function instead.", funcName); } return DynValue.NewTupleNested(DynValue.True, ret); } catch (ScriptRuntimeException ex) { executionContext.PerformMessageDecorationBeforeUnwind(handlerBeforeUnwind, ex); return DynValue.NewTupleNested(DynValue.False, DynValue.NewString(ex.DecoratedMessage)); } } if (args[0].Type != DataType.Function) { return DynValue.NewTupleNested(DynValue.False, DynValue.NewString("attempt to " + funcName + " a non-function")); } return DynValue.NewTailCallReq(new TailCallData { Args = a, Function = v, Continuation = new CallbackFunction(pcall_continuation, funcName), ErrorHandler = new CallbackFunction(pcall_onerror, funcName), ErrorHandlerBeforeUnwind = handlerBeforeUnwind }); }
public static DynValue setuservalue(ScriptExecutionContext executionContext, CallbackArguments args) { var v = args.AsType(0, "setuservalue", DataType.UserData, false); var t = args.AsType(0, "setuservalue", DataType.Table, true); return v.UserData.UserValue = t; }
public static DynValue rawget(ScriptExecutionContext executionContext, CallbackArguments args) { DynValue table = args.AsType(0, "rawget", DataType.Table); DynValue index = args[1]; return table.Table.Get(index); }
public static DynValue @char(ScriptExecutionContext executionContext, CallbackArguments args) { var sb = new StringBuilder(args.Count); for (var i = 0; i < args.Count; i++) { var v = args[i]; var d = 0d; if (v.Type == DataType.String) { var nd = v.CastToNumber(); if (nd == null) args.AsType(i, "char", DataType.Number, false); else d = nd.Value; } else { args.AsType(i, "char", DataType.Number, false); d = v.Number; } sb.Append((char) (d)); } return DynValue.NewString(sb.ToString()); }
public override DynValue Eval(ScriptExecutionContext context) { if (expressions.Count >= 1) return expressions[0].Eval(context); return DynValue.Void; }
public static DynValue ipairs(ScriptExecutionContext executionContext, CallbackArguments args) { var table = args[0]; var meta = executionContext.GetMetamethodTailCall(table, "__ipairs", args.GetArray()); return meta ?? DynValue.NewTuple(DynValue.NewCallback(__next_i), table, DynValue.NewNumber(0)); }
public static DynValue pairs(ScriptExecutionContext executionContext, CallbackArguments args) { DynValue table = args[0]; DynValue meta = executionContext.GetMetamethodTailCall(table, "__pairs", args.GetArray()); return meta ?? DynValue.NewTuple(DynValue.NewCallback(next), table); }
public override DynValue Eval(ScriptExecutionContext context) { var b = m_BaseExp.Eval(context).ToScalar(); var i = m_IndexExp != null ? m_IndexExp.Eval(context).ToScalar() : DynValue.NewString(m_Name); if (b.Type != DataType.Table) throw new DynamicExpressionException("Attempt to index non-table."); if (i.IsNilOrNan()) throw new DynamicExpressionException("Attempt to index with nil or nan key."); return b.Table.Get(i) ?? DynValue.Nil; }
public static DynValue @byte(ScriptExecutionContext executionContext, CallbackArguments args) { var vs = args.AsType(0, "byte", DataType.String, false); var vi = args.AsType(1, "byte", DataType.Number, true); var vj = args.AsType(2, "byte", DataType.Number, true); return PerformByteLike(vs, vi, vj, i => Unicode2Ascii(i)); }
public static DynValue rawset(ScriptExecutionContext executionContext, CallbackArguments args) { var table = args.AsType(0, "rawset", DataType.Table); var index = args[1]; table.Table.Set(index, args[2]); return table; }
public static DynValue getuservalue(ScriptExecutionContext executionContext, CallbackArguments args) { var v = args[0]; if (v.Type != DataType.UserData) return DynValue.Nil; return v.UserData.UserValue ?? DynValue.Nil; }
/// <summary> /// The internal callback which actually executes the method /// </summary> /// <param name="script">The script.</param> /// <param name="obj">The object.</param> /// <param name="context">The context.</param> /// <param name="args">The arguments.</param> /// <returns></returns> public override DynValue Execute(Script script, object obj, ScriptExecutionContext context, CallbackArguments args) { if (m_CallbackFunc != null) { var retv = m_CallbackFunc(obj, context, args); return ClrToScriptConversions.ObjectToDynValue(script, retv); } return DynValue.Void; }
public static DynValue difftime(ScriptExecutionContext executionContext, CallbackArguments args) { DynValue t2 = args.AsType(0, "difftime", DataType.Number, false); DynValue t1 = args.AsType(1, "difftime", DataType.Number, true); if (t1.IsNil()) return DynValue.NewNumber(t2.Number); return DynValue.NewNumber(t2.Number - t1.Number); }
internal LuaState(ScriptExecutionContext executionContext, CallbackArguments args, string functionName) { ExecutionContext = executionContext; m_Stack = new List<DynValue>(16); for (int i = 0; i < args.Count; i++) m_Stack.Add(args[i]); FunctionName = functionName; }
public static DynValue getenv(ScriptExecutionContext executionContext, CallbackArguments args) { var varName = args.AsType(0, "getenv", DataType.String, false); var val = Script.GlobalOptions.Platform.GetEnvironmentVariable(varName.String); if (val == null) return DynValue.Nil; return DynValue.NewString(val); }
public static DynValue wrap(ScriptExecutionContext executionContext, CallbackArguments args) { if (args[0].Type != DataType.Function && args[0].Type != DataType.ClrFunction) args.AsType(0, "wrap", DataType.Function); // this throws DynValue v = create(executionContext, args); DynValue c = DynValue.NewCallback(__wrap_wrapper); c.Callback.AdditionalData = v; return c; }
public static DynValue next(ScriptExecutionContext executionContext, CallbackArguments args) { var table = args.AsType(0, "next", DataType.Table); var index = args[1]; var pair = table.Table.NextKey(index); if (pair.HasValue) return DynValue.NewTuple(pair.Value.Key, pair.Value.Value); throw new ScriptRuntimeException("invalid key to 'next'"); }
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; }
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; }
public static DynValue exit(ScriptExecutionContext executionContext, CallbackArguments args) { DynValue v_exitCode = args.AsType(0, "exit", DataType.Number, true); int exitCode = 0; if (v_exitCode.IsNotNil()) exitCode = (int)v_exitCode.Number; Script.GlobalOptions.Platform.OS_ExitFast(exitCode); throw new InvalidOperationException("Unreachable code.. reached."); }
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; }
public static DynValue time(ScriptExecutionContext executionContext, CallbackArguments args) { DateTime date = DateTime.UtcNow; if (args.Count > 0) { DynValue vt = args.AsType(0, "time", DataType.Table, true); if (vt.Type == DataType.Table) date = ParseTimeTable(vt.Table); } return GetUnixTime(date); }
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); } }
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() + ")"); }
public override SymbolRef FindDynamic(ScriptExecutionContext context) { return(context.FindSymbolByName(_varName)); }
public static DynValue __wrap_wrapper(ScriptExecutionContext executionContext, CallbackArguments args) { DynValue handle = (DynValue)executionContext.AdditionalData; return(handle.Coroutine.Resume(args.GetArray())); }
/// <summary> /// Calculates the score for the overload. /// </summary> /// <param name="context">The context.</param> /// <param name="args">The arguments.</param> /// <param name="method">The method.</param> /// <param name="isExtMethod">if set to <c>true</c>, is an extension method.</param> /// <returns></returns> private int CalcScoreForOverload(ScriptExecutionContext context, CallbackArguments args, IOverloadableMemberDescriptor method, bool isExtMethod) { int totalScore = ScriptToClrConversions.WEIGHT_EXACT_MATCH; int argsBase = args.IsMethodCall ? 1 : 0; int argsCnt = argsBase; bool varArgsUsed = false; for (int i = 0; i < method.Parameters.Length; i++) { if (isExtMethod && i == 0) { continue; } if (method.Parameters[i].IsOut) { continue; } Type parameterType = method.Parameters[i].Type; if ((parameterType == typeof(Script)) || (parameterType == typeof(ScriptExecutionContext)) || (parameterType == typeof(CallbackArguments))) { continue; } if (i == method.Parameters.Length - 1 && method.VarArgsArrayType != null) { int varargCnt = 0; DynValue firstArg = null; int scoreBeforeVargars = totalScore; // update score for varargs while (true) { var arg = args.RawGet(argsCnt, false); if (arg == null) { break; } if (firstArg == null) { firstArg = arg; } argsCnt += 1; varargCnt += 1; int score = CalcScoreForSingleArgument(method.Parameters[i], method.VarArgsElementType, arg, isOptional: false); totalScore = Math.Min(totalScore, score); } // check if exact-match if (varargCnt == 1) { if (firstArg.Type == DataType.UserData && firstArg.UserData.Object != null) { if (Framework.Do.IsAssignableFrom(method.VarArgsArrayType, firstArg.UserData.Object.GetType())) { totalScore = scoreBeforeVargars; continue; } } } // apply varargs penalty to score if (varargCnt == 0) { totalScore = Math.Min(totalScore, ScriptToClrConversions.WEIGHT_VARARGS_EMPTY); } varArgsUsed = true; } else { var arg = args.RawGet(argsCnt, false) ?? DynValue.Void; int score = CalcScoreForSingleArgument(method.Parameters[i], parameterType, arg, method.Parameters[i].HasDefaultValue); totalScore = Math.Min(totalScore, score); argsCnt += 1; } } if (totalScore > 0) { if ((args.Count - argsBase) <= method.Parameters.Length) { totalScore += ScriptToClrConversions.WEIGHT_NO_EXTRA_PARAMS_BONUS; totalScore *= 1000; } else if (varArgsUsed) { totalScore -= ScriptToClrConversions.WEIGHT_VARARGS_MALUS; totalScore *= 1000; } else { totalScore *= 1000; totalScore -= ScriptToClrConversions.WEIGHT_EXTRA_PARAMS_MALUS * ((args.Count - argsBase) - method.Parameters.Length); totalScore = Math.Max(1, totalScore); } } #if DEBUG_OVERLOAD_RESOLVER System.Diagnostics.Debug.WriteLine(string.Format("[OVERLOAD] : Score {0} for method {1}", totalScore, method.SortDiscriminant)); #endif return(totalScore); }
public static void DisableScript(ScriptExecutionContext context, [ScriptArgumentType(ScriptArgumentType.ScriptName)] string scriptName) { EnableScriptInternal(context, scriptName, false); }
public DynValue read(ScriptExecutionContext executionContext, CallbackArguments args) { if (args.Count == 0) { string str = ReadLine(); if (str == null) { return(DynValue.Nil); } str = str.TrimEnd('\n', '\r'); return(DynValue.NewString(str)); } else { List <DynValue> rets = new List <DynValue>(); for (int i = 0; i < args.Count; i++) { DynValue v; if (args[i].Type == DataType.Number) { if (Eof()) { return(DynValue.Nil); } int howmany = (int)args[i].Number; string str = ReadBuffer(howmany); v = DynValue.NewString(str); } else { string opt = args.AsType(i, "read", DataType.String, false).String; if (Eof()) { v = opt.StartsWith("*a") ? DynValue.NewString("") : DynValue.Nil; } else if (opt.StartsWith("*n")) { double?d = ReadNumber(); if (d.HasValue) { v = DynValue.NewNumber(d.Value); } else { v = DynValue.Nil; } } else if (opt.StartsWith("*a")) { string str = ReadToEnd(); v = DynValue.NewString(str); } else if (opt.StartsWith("*l")) { string str = ReadLine(); str = str.TrimEnd('\n', '\r'); v = DynValue.NewString(str); } else if (opt.StartsWith("*L")) { string str = ReadLine(); str = str.TrimEnd('\n', '\r'); str += "\n"; v = DynValue.NewString(str); } else { throw ScriptRuntimeException.BadArgument(i, "read", "invalid option"); } } rets.Add(v); } return(DynValue.NewTuple(rets.ToArray())); } }
public static DynValue getinfo(ScriptExecutionContext executionContext, CallbackArguments args) { Coroutine cor = executionContext.GetCallingCoroutine(); int vfArgIdx = 0; if (args[0].Type == DataType.Thread) { cor = args[0].Coroutine; } DynValue vf = args[vfArgIdx + 0]; DynValue vwhat = args[vfArgIdx + 1]; //args.AsType(vfArgIdx + 1, "getinfo", DataType.String, true); string what = vwhat.CastToString() ?? "nfSlu"; DynValue vt = DynValue.NewTable(executionContext.GetScript()); Table t = vt.Table; if (vf.Type == DataType.Function || vf.Type == DataType.ClrFunction) { GetInfoAboutFunction(t, vf, what, executionContext); return(vt); } else if (vf.Type == DataType.Number) { var stackTrace = cor.GetStackTrace((int)vf.Number); if (stackTrace.Length <= 0) { return(DynValue.Nil); } var info = stackTrace[0]; if (what.Contains("S")) { var source = executionContext.OwnerScript.GetSourceCode(info.Location.SourceIdx); if (source != null) { t["source"] = source != null ? source.Name : "[C]"; t["short_src"] = source.Name.Substring(0, Math.Min(source.Name.Length, 60)); t["what"] = "Lua"; } else { t["source"] = "[C]"; t["short_src"] = "[C]"; t["what"] = "C"; } } if (what.Contains("L")) { } if (what.Contains("n")) { } if (what.Contains("u")) { } t["linedefined"] = info.Location.FromLine; t["lastlinedefined"] = info.Location.ToLine; return(vt); } return(DynValue.Nil); }
public override DynValue Eval(ScriptExecutionContext context) { return(context.EvaluateSymbolByName(_varName)); }
private List <WatchItem> Debugger_RefreshWatches(ScriptExecutionContext context, List <DynamicExpression> watchList) { return(watchList.Select(w => Debugger_RefreshWatch(context, w)).ToList()); }
private DynValue LuaIteratorCallback(ScriptExecutionContext executionContext, CallbackArguments args) { m_Prev = this.GetNext(m_Prev); return(m_Prev); }
public static DynValue loadsafe(ScriptExecutionContext executionContext, CallbackArguments args) { return(load_impl(executionContext, args, GetSafeDefaultEnv(executionContext))); }
private static DynValue gmatch_aux_2(ScriptExecutionContext executionContext, CallbackArguments args) { return(executionContext.EmulateClassicCall(args, "gmatch", L => gmatch_aux(L, (GMatchAuxData)executionContext.AdditionalData))); }
public static void NoOp(ScriptExecutionContext context) { }
public static DynValue len(ScriptExecutionContext executionContext, CallbackArguments args) { DynValue vs = args.AsType(0, "len", DataType.String, false); return(DynValue.NewNumber(vs.String.Length)); }
public static DynValue pack(ScriptExecutionContext executionContext, CallbackArguments args) { return(TableModule.pack(executionContext, args)); }
public static DynValue getregistry(ScriptExecutionContext executionContext, CallbackArguments args) { return(DynValue.NewTable(executionContext.GetScript().Registry)); }
public static DynValue sqrt(ScriptExecutionContext executionContext, CallbackArguments args) { return(exec1(args, "sqrt", d => Math.Sqrt(d))); }
private static void GetInfoAboutFunction(Table infoTable, DynValue function, string what, ScriptExecutionContext executionContext) { if (function.Type == DataType.Function) { Closure f = function.Function; var sourceRef = executionContext.GetFunctionSourceCodeRef(f); var source = executionContext.OwnerScript.GetSourceCode(sourceRef.SourceIdx); if (what.Contains("S")) { infoTable["source"] = source.Name; infoTable["short_src"] = source.Name.Substring(0, Math.Min(source.Name.Length, 60)); infoTable["what"] = "Lua"; } if (what.Contains("L")) { var lines = new Table(executionContext.OwnerScript); for (int i = sourceRef.FromLine; i <= sourceRef.ToLine; i++) { lines.Append(DynValue.NewString(source.Lines[i])); } infoTable["activelines"] = lines; } if (what.Contains("n")) { var name = executionContext.GetFunctionName(f); infoTable["name"] = name; var symbolRef = executionContext.FindSymbolByName(name); switch (symbolRef.Type) { case SymbolRefType.Global: infoTable["namewhat"] = "global"; break; case SymbolRefType.Local: infoTable["namewhat"] = "local"; break; case SymbolRefType.DefaultEnv: infoTable["namewhat"] = "field"; break; } } if (what.Contains("u")) { infoTable["nups"] = f.GetUpvaluesCount(); } infoTable["linedefined"] = sourceRef.FromLine; infoTable["lastlinedefined"] = sourceRef.ToLine; } else if (function.Type == DataType.ClrFunction) { CallbackFunction f = function.Callback; if (what.Contains("S")) { infoTable["source"] = "[C]"; infoTable["short_src"] = "[C]"; infoTable["what"] = "C"; } if (what.Contains("n")) { var symbolRef = executionContext.FindSymbolByName(f.Name); infoTable["name"] = f.Name; switch (symbolRef.Type) { case SymbolRefType.Global: infoTable["namewhat"] = "global"; break; case SymbolRefType.Local: infoTable["namewhat"] = "local"; break; case SymbolRefType.DefaultEnv: infoTable["namewhat"] = "field"; break; } } } }
public static DynValue load(ScriptExecutionContext executionContext, CallbackArguments args) { return(load_impl(executionContext, args, null)); }
public static DynValue traceback(ScriptExecutionContext executionContext, CallbackArguments args) { StringBuilder sb = new StringBuilder(); DynValue vmessage = args[0]; DynValue vlevel = args[1]; double defaultSkip = 1.0; Coroutine cor = executionContext.GetCallingCoroutine(); if (vmessage.Type == DataType.Thread) { cor = vmessage.Coroutine; vmessage = args[1]; vlevel = args[2]; defaultSkip = 0.0; } if (vmessage.IsNotNil() && vmessage.Type != DataType.String && vmessage.Type != DataType.Number) { return(vmessage); } string message = vmessage.CastToString(); int skip = (int)((vlevel.CastToNumber()) ?? defaultSkip); WatchItem[] stacktrace = cor.GetStackTrace(Math.Max(0, skip)); if (message != null) { sb.AppendLine(message); } sb.AppendLine("stack traceback:"); foreach (WatchItem wi in stacktrace) { string name; if (wi.Name == null) { if (wi.RetAddress < 0) { name = "main chunk"; } else { name = "?"; } } else { name = "function '" + wi.Name + "'"; } string loc = wi.Location != null?wi.Location.FormatLocation(executionContext.GetScript()) : "[clr]"; sb.AppendFormat("\t{0}: in {1}\n", loc, name); } return(DynValue.NewString(sb)); }
public static DynValue acos(ScriptExecutionContext executionContext, CallbackArguments args) { return(exec1(args, "acos", d => Math.Acos(d))); }
public static DynValue format(ScriptExecutionContext executionContext, CallbackArguments args) { return(executionContext.EmulateClassicCall(args, "format", KopiLua_StringLib.str_format)); }
public static void SetFlag(ScriptExecutionContext context, [ScriptArgumentType(ScriptArgumentType.FlagName)] string flagName, bool flagValue) { context.Scripting.Flags[flagName] = flagValue; }
public override DynValue Eval(ScriptExecutionContext context) { return(expression.Eval(context).ToScalar()); }
private DynValue PerformBinaryOperationU(string funcName, ScriptExecutionContext ctx, CallbackArguments args, Func <ulong, ulong, ulong> operation) { return(PerformBinaryOperationU(funcName, ctx, args, (v1, v2) => CreateValueUnsigned(operation(v1, v2)))); }
public static DynValue tanh(ScriptExecutionContext executionContext, CallbackArguments args) { return(exec1(args, "tanh", d => Math.Tanh(d))); }
/// <summary> /// Performs the overloaded call. /// </summary> /// <param name="script">The script.</param> /// <param name="obj">The object.</param> /// <param name="context">The context.</param> /// <param name="args">The arguments.</param> /// <returns></returns> /// <exception cref="ScriptRuntimeException">function call doesn't match any overload</exception> private DynValue PerformOverloadedCall(Script script, object obj, ScriptExecutionContext context, CallbackArguments args) { bool extMethodCacheNotExpired = IgnoreExtensionMethods || (obj == null) || m_ExtensionMethodVersion == UserData.GetExtensionMethodsChangeVersion(); // common case, let's optimize for it if (m_Overloads.Count == 1 && m_ExtOverloads.Count == 0 && extMethodCacheNotExpired) { return(m_Overloads[0].Execute(script, obj, context, args)); } if (m_Unsorted) { m_Overloads.Sort(new OverloadableMemberDescriptorComparer()); m_Unsorted = false; } if (extMethodCacheNotExpired) { for (int i = 0; i < m_Cache.Length; i++) { if (m_Cache[i] != null && CheckMatch(obj != null, args, m_Cache[i])) { #if DEBUG_OVERLOAD_RESOLVER System.Diagnostics.Debug.WriteLine(string.Format("[OVERLOAD] : CACHED! slot {0}, hits: {1}", i, m_CacheHits)); #endif return(m_Cache[i].Method.Execute(script, obj, context, args)); } } } // resolve on overloads first int maxScore = 0; IOverloadableMemberDescriptor bestOverload = null; for (int i = 0; i < m_Overloads.Count; i++) { if (obj != null || m_Overloads[i].IsStatic) { int score = CalcScoreForOverload(context, args, m_Overloads[i], false); if (score > maxScore) { maxScore = score; bestOverload = m_Overloads[i]; } } } if (!IgnoreExtensionMethods && (obj != null)) { if (!extMethodCacheNotExpired) { m_ExtensionMethodVersion = UserData.GetExtensionMethodsChangeVersion(); m_ExtOverloads = UserData.GetExtensionMethodsByNameAndType(this.Name, this.DeclaringType); } for (int i = 0; i < m_ExtOverloads.Count; i++) { int score = CalcScoreForOverload(context, args, m_ExtOverloads[i], true); if (score > maxScore) { maxScore = score; bestOverload = m_ExtOverloads[i]; } } } if (bestOverload != null) { Cache(obj != null, args, bestOverload); return(bestOverload.Execute(script, obj, context, args)); } throw new ScriptRuntimeException("function call doesn't match any overload"); }
public static DynValue running(ScriptExecutionContext executionContext, CallbackArguments args) { Coroutine C = executionContext.GetCallingCoroutine(); return(DynValue.NewTuple(DynValue.NewCoroutine(C), DynValue.NewBoolean(C.State == CoroutineState.Main))); }
public static DynValue yield(ScriptExecutionContext executionContext, CallbackArguments args) { return(DynValue.NewYieldReq(args.GetArray())); }
public static void CallSubroutine(ScriptExecutionContext context, [ScriptArgumentType(ScriptArgumentType.SubroutineName)] string scriptName) { context.Scripting.FindScript(scriptName)?.ExecuteAsSubroutine(context); }
public static DynValue upper(ScriptExecutionContext executionContext, CallbackArguments args) { DynValue arg_s = args.AsType(0, "upper", DataType.String, false); return(DynValue.NewString(arg_s.String.ToUpper())); }