} // proc WriteAttributeString /// <summary>Convert the xml node to an property dictionary.</summary> /// <param name="attributes"></param> /// <param name="wellKnownProperties"></param> /// <returns></returns> public static IPropertyReadOnlyDictionary ToPropertyDictionary(this IEnumerable <XElement> attributes, params KeyValuePair <string, Type>[] wellKnownProperties) { var props = new PropertyDictionary(); foreach (var x in attributes) { var propertyName = x.GetAttribute <string>("name", null); if (String.IsNullOrEmpty(propertyName)) { throw new ArgumentException("@name is missing."); } Type dataType; var wellKnownPropertyIndex = Array.FindIndex(wellKnownProperties, c => String.Compare(c.Key, propertyName, StringComparison.OrdinalIgnoreCase) == 0); if (wellKnownPropertyIndex == -1) { dataType = LuaType.GetType(x.GetAttribute("dataType", "string")); } else { dataType = wellKnownProperties[wellKnownPropertyIndex].Value; } props.SetProperty(propertyName, dataType, x.Value); } return(props); } // func IPropertyReadOnlyDictionary
/// <summary> /// Creates the lua code function. /// </summary> /// <param name="dte">The DTE.</param> /// <param name="parent">The parent.</param> /// <param name="name">The name.</param> /// <param name="returnType">Type of the return.</param> /// <param name="isLocal">if set to <c>true</c> [is local].</param> /// <param name="function">The function.</param> /// <returns></returns> public static LuaCodeFunction CreateLuaCodeFunction( DTE dte, CodeElement parent, string name, LuaType returnType, bool isLocal, FunctionDeclaration function) { return(CreateLuaCodeFunction(dte, parent, name, returnType, isLocal ? vsCMAccess.vsCMAccessPrivate : vsCMAccess.vsCMAccessProject, vsCMFunction.vsCMFunctionFunction, function)); }
private void ExtendLuaEnvironment(LuaGlobal g) { g.RegisterPackage("os", typeof(OperationSystemPackage)); g.RegisterPackage("log", typeof(ConsolePackage)); foreach (var package in _userProvidedPackages) { g.RegisterPackage(package.Key, package.Value); } // extension methods need to be registered separately through RegisterTypeExtension call) foreach (var extensionClass in _userProvidedExtensionMethodClasses) { LuaType.RegisterTypeExtension(extensionClass); } // tables can be registered directly dynamic dg = g; foreach (var pair in _userProvidedTables) { dg[pair.Key] = pair.Value; } // delegates need to be registered with the LuaGlobal foreach (var pair in _userProvidedDelegate) { g.DefineFunction(pair.Key, pair.Value); } }
private static bool IsEditableLuaType(LuaType type) { return ((type == LuaType.LUA_TSTRING) || (type == LuaType.LUA_TBOOLEAN) || (type == LuaType.LUA_TNUMBER)); }
public void ExtensionTest01() { LuaType.RegisterTypeExtension(typeof(TypeExt)); TestCode("return 'Hallo0':LetterCount();", 5); TestCode("t = 'Hallo0'; return t:LetterCount();", 5); }
} // proc FreeAndNil #endregion #region -- ChangeType ------------------------------------------------------------- /// <summary>Konvertiert den Datentyp zum gewünschten Ziel-Datentyp.</summary> /// <param name="value"></param> /// <param name="typeTo"></param> /// <returns></returns> /// <remarks>Es wird der Lua Converter verwendet, da er Schnittstelle, Operatoren und allgemeine Regeln beherrscht ohne auf das TypeDescriptor-Framework zu verweisen.</remarks> public static object ChangeType(object value, Type typeTo) { if (typeTo == typeof(bool) && value is string) { var t = (string)value; return(t == "1" || String.Compare(t, Boolean.TrueString, StringComparison.OrdinalIgnoreCase) == 0); } else if (typeTo == typeof(DateTimeOffset) && (value == null || value is string)) { return(value == null ? DateTimeOffset.MinValue : DateTimeOffset.Parse((string)value, CultureInfo.InvariantCulture)); } else if (typeTo == typeof(XDocument) && (value == null || value is string)) { return(value == null ? null : XDocument.Parse((string)value)); } else if (typeTo == typeof(string) && (value == null || value is XDocument)) { return(value == null ? null : value.ToString()); } else if (typeTo == typeof(Type) && (value == null || value is string)) { return(value == null ? null : LuaType.GetType((string)value, lateAllowed: false).Type); } else if (typeTo == typeof(string) && value is Type) { return(LuaType.GetType((Type)value).AliasOrFullName); } else { return(Lua.RtConvertValue(value, typeTo)); } } // func ChangeType
/// <summary> /// Creates the lua code function. /// </summary> /// <param name="dte">The DTE.</param> /// <param name="parent">The parent.</param> /// <param name="name">The name.</param> /// <param name="returnType">Type of the return.</param> /// <param name="access">The access.</param> /// <param name="function">The function.</param> /// <returns></returns> public static LuaCodeFunction CreateLuaCodeFunction( DTE dte, CodeElement parent, string name, LuaType returnType, vsCMAccess access, FunctionDeclaration function) { return(CreateLuaCodeFunction(dte, parent, name, returnType, access, vsCMFunction.vsCMFunctionFunction, function)); }
} // func GetClientRelationFromServerRelation /// <summary></summary> /// <param name="xTable"></param> public void WriteSchema(XElement xTable) { var clientDataType = Meta.GetProperty <string>("clientDataType", null); var xColumn = new XElement("column", new XAttribute("name", Name), new XAttribute("dataType", clientDataType ?? LuaType.GetType(DataType).AliasOrFullName) ); if (IsPrimaryKey) { xColumn.Add(new XAttribute("isPrimary", IsPrimaryKey)); } if (IsIdentity) { xColumn.Add(new XAttribute("isIdentity", IsIdentity)); } if (IsRelationColumn) { xColumn.Add(new XAttribute("parentRelationName", parentRelationName)); xColumn.Add(new XAttribute("parentRelationType", GetClientRelationFromServerRelation(parentType))); xColumn.Add(new XAttribute("parentTable", ParentColumn.Table.Name)); xColumn.Add(new XAttribute("parentColumn", ParentColumn.Name)); } xTable.Add(xColumn); // meta data PpsDataSetServerDefinition.WriteSchemaMetaInfo(xColumn, metaInfo); } // proc WriteSchema
public void L_CheckType(int index, LuaType t) { if (API.Type(index) != t) { TagError(index, t); } }
} // proc UpdateData private bool TryParseColumn(XElement cur, out SimpleDataColumn col) { var name = cur.GetAttribute("name", null); if (String.IsNullOrEmpty(name)) { goto Error; } var type = LuaType.GetType(cur.GetAttribute("type", null), lateAllowed: false); var attributes = new PropertyDictionary(); foreach (var xAttr in cur.Elements("attribute")) { if (TryParseAttribute(xAttr, out var attr)) { attributes.SetProperty(attr); } } col = new SimpleDataColumn(name, type, attributes); return(true); Error: col = null; return(false); } // func TryParseColumn
bool ILuaAPI.IsNoneOrNil(int index) { LuaType t = API.Type(index); return(t == LuaType.LUA_TNONE || t == LuaType.LUA_TNIL); }
public LuaEngine(IServiceProvider sp, string name) : base(sp, name) { // create the state this.propertyScriptCount = new SimpleConfigItemProperty <int>(this, "tw_luaengine_scripts", "Skripte", "Lua-Engine", "Anzahl der aktiven Scripte.", "{0:N0}", 0); // create the lists this.scripts = new DEList <LuaScript>(this, "tw_scripts", "Scriptlist"); this.globals = new DEList <LuaAttachedGlobal>(this, "tw_globals", "Attached scripts"); // Register the service var sc = sp.GetService <IServiceContainer>(true); sc.AddService(typeof(IDELuaEngine), this); // register context extensions LuaType.RegisterTypeExtension(typeof(HttpResponseHelper)); // create the debug options debugHook = new LuaEngineTraceLineDebugger(this); debugOptions = new LuaCompileOptions(); debugOptions.DebugEngine = debugHook; // update lua runtime sp.GetService <DEServer>(true).UpdateLuaRuntime(lua); } // ctor
public LuaRef CheckType(LuaType type) { PushToStack(); luaL_checktype(L, -1, (int)(type)); lua_pop(L, 1); return(this); }
} // func GetLogPropertyInfo public static async Task GetLogPropertiesAsync(DEHttpClient http, string path, Action <string, LogProperty> process = null) { var xProperties = await http.GetXmlAsync(Program.MakeUri(path, new PropertyValue("action", "listget"), new PropertyValue("id", "tw_properties") ), rootName : "list"); var properties = xProperties.Element("items")?.Elements("property"); if (properties != null) { foreach (var x in properties) { var name = x.GetAttribute("name", null); if (name == null) { continue; } // parse info var propertyInfo = new LogPropertyInfo(name, x.GetAttribute("displayname", name), LuaType.GetType(x.GetAttribute("type", "string"), lateAllowed: true).Type, x.GetAttribute("description", name), x.GetAttribute("format", null) ); UpdatePropertyInfo(propertyInfo); // process value process?.Invoke(path, new LogProperty(propertyInfo, x.Value)); } } } // func GetLogProperties
} // proc WriteType public void WriteItem(DEListItemWriter xml, object item) { var caItem = (KeyValuePair <string, DEConfigAction>)item; var ca = caItem.Value; xml.WriteStartProperty("action"); xml.WriteAttributeProperty("id", caItem.Key); xml.WriteAttributeProperty("description", ca.Description); xml.WriteAttributeProperty("safecall", ca.IsSafeCall.ToString()); xml.WriteAttributeProperty("security", ca.SecurityToken); xml.WriteAttributeProperty("return", ca.MethodDescription.ReturnType.ToString()); xml.WriteStartProperty("arguments"); foreach (var p in ca.MethodDescription.GetParameters()) { xml.WriteStartProperty("argument"); xml.WriteAttributeProperty("name", p.Name); xml.WriteAttributeProperty("type", LuaType.GetType(p.ParameterType).AliasOrFullName); if (p.DefaultValue != null) { xml.WriteValue(p.DefaultValue); } xml.WriteEndProperty(); } xml.WriteEndProperty(); xml.WriteEndProperty(); } // proc WriteItem
static int print(IntPtr p) { var state = Lua.FromIntPtr(p); int n = state.GetTop(); /* number of arguments */ int i; for (i = 1; i <= n; i++) { LuaType type = state.Type(i); switch (type) { case LuaType.Nil: Trace.Write("nil"); break; case LuaType.String: string s = state.ToString(i, false); Trace.Write(s); break; case LuaType.Number: double number = state.ToNumber(i); Trace.Write(number); break; } } Trace.WriteLine("\n"); return(0); }
} // func InvokeExpression private static Expression InvokeMemberExpression(Scope scope, Token tStart, Expression instance, string sMember, InvokeResult result, ArgumentsList arguments) { if (LuaEmit.IsDynamicType(instance.Type)) { return(EnsureInvokeResult(scope, tStart, DynamicExpression.Dynamic(scope.Runtime.GetInvokeMemberBinder(sMember, arguments.CallInfo), typeof(object), new Expression[] { ConvertExpression(scope.Runtime, tStart, instance, typeof(object)) }.Concat( from c in arguments.Expressions select Lua.EnsureType(c, typeof(object)) ).ToArray() ), result, instance, sMember )); } else { // look up the method MethodInfo method = LuaEmit.FindMethod( LuaType.GetType(instance.Type).GetInstanceMethods(sMember, false), arguments.CallInfo, arguments.Expressions, getExpressionTypeFunction, true); if (method != null) { return(EnsureInvokeResult(scope, tStart, SafeExpression(() => InvokeMemberExpressionBind(method, scope.Runtime, instance, arguments), tStart), result, instance, sMember)); } else { return(InvokeMemberExpressionDynamic(scope, tStart, instance, sMember, result, arguments)); } } } // func InvokeMemberExpression
} // proc Execute private XElement CreateException(XElement x, Exception e) { var aggE = e as AggregateException; if (aggE != null) { var enumerator = aggE.InnerExceptions.GetEnumerator(); if (enumerator.MoveNext()) { CreateException(x, enumerator.Current); while (enumerator.MoveNext()) { x.Add(CreateException(new XElement("innerException"), enumerator.Current)); } } else { x.Add(new XAttribute("message", e.Message)); } } else { x.Add(new XAttribute("message", e.Message)); x.Add(new XAttribute("type", LuaType.GetType(e.GetType()).AliasOrFullName)); var data = LuaExceptionData.GetData(e); x.Add(new XElement("stackTrace", data == null ? e.StackTrace : data.StackTrace)); if (e.InnerException != null) { x.Add(CreateException(new XElement("innerException"), e.InnerException)); } } return(x); } // proc CreateException
/// <summary> /// Creates the variable. /// </summary> /// <param name="dte">The DTE.</param> /// <param name="parent">The parent.</param> /// <param name="name">The name.</param> /// <param name="type">The type.</param> /// <param name="isLocal">if set to <c>true</c> [is local].</param> /// <param name="variable">The variable.</param> /// <returns></returns> public static LuaCodeVariable CreateVariable( DTE dte, CodeElement parent, string name, LuaType type, bool isLocal, Variable variable) { return(CreateVariable(dte, parent, name, type, isLocal ? vsCMAccess.vsCMAccessPrivate : vsCMAccess.vsCMAccessProject, variable)); }
// To be used only within a proper error handled context // (LuaCLRFunctions and LuaCLR*Proxies) public void CheckArg(LuaType type, int index = -1) { if (Type(index) != type) { throw new LuaException($"Argument #{index}: expected {type}, got {Type(index)}"); } }
private static string stack_dump_value(ILuaState lua, int idx) { #if UNITY_EDITOR LuaType t = lua.Type(idx); switch (t) { case LuaType.LUA_TNIL: return("nil"); case LuaType.LUA_TBOOLEAN: return(string.Format("{0}", lua.ToBoolean(idx))); case LuaType.LUA_TUINT64: return(string.Format("{0}", lua.ToUInt64(idx))); case LuaType.LUA_TNUMBER: return(string.Format("{0}", lua.ToNumber(idx))); default: return("--"); } #else return(""); #endif }
static void SetCallBackParameter(LuaState lua, object[] p, ParameterInfo[] ps, int indexInStack) { LuaType paraType = LuaType.LUA_TNONE; for (int i = 0; i < ps.Length; i++) { int index = indexInStack; paraType = lua.Type(index); if (ps[i].ParameterType == typeof(object)) { if (paraType == LuaType.LUA_TNUMBER) { p[i] = (float)lua.ToNumber(index); } else if (paraType == LuaType.LUA_TSTRING) { p[i] = lua.ToString(index); } else if (paraType == LuaType.LUA_TBOOLEAN) { p[i] = lua.ToBoolean(index); } else if (paraType == LuaType.LUA_TUSERDATA) { p[i] = lua.ToUserDataObject(index); } } else { if (paraType == LuaType.LUA_TNUMBER) { if (ps[i].ParameterType == typeof(int)) { p[i] = lua.ToInteger(index); } else if (ps[i].ParameterType == typeof(float)) { p[i] = (float)lua.ToNumber(index); } } else { if (paraType == LuaType.LUA_TSTRING) { p[i] = lua.ToString(index); } else if (paraType == LuaType.LUA_TBOOLEAN) { p[i] = lua.ToBoolean(index); } else if (paraType == LuaType.LUA_TUSERDATA) { p[i] = lua.ToUserDataObject(index); } } } } }
public static int B_Type(ILuaState lua) { LuaType t = lua.Type(1); string tname = lua.TypeName(t); lua.PushString(tname); return(1); }
/// <summary> /// Creates the lua code function. /// </summary> /// <param name="dte">The DTE.</param> /// <param name="parent">The parent.</param> /// <param name="name">The name.</param> /// <param name="returnType">Type of the return.</param> /// <param name="access">The access.</param> /// <param name="kind">The kind.</param> /// <param name="function">The function.</param> /// <returns></returns> public static LuaCodeFunction CreateLuaCodeFunction( DTE dte, CodeElement parent, string name, LuaType returnType, vsCMAccess access, vsCMFunction kind, FunctionDeclaration function) { var result = new LuaCodeFunction(dte, parent, name, kind, new LuaCodeTypeRef(dte, LuaDeclaredType.Find(returnType.ToString())), access, function); return(result); }
/// <summary> /// Adds fields to the table object. /// </summary> /// <param name="variableName">Field variable name.</param> /// <param name="type">Field variable type.</param> /// <param name="variable">Optional. Field variable Node object.</param> /// <returns></returns> public CodeVariable AddInitVariable(string variableName, LuaType type, Variable variable) { var result = new LuaCodeVariable(DTE, parent, variableName, new LuaCodeTypeRef(DTE, LuaDeclaredType.Find(type.ToString())), vsCMAccess.vsCMAccessPublic, variable); AddInitVariable(result); return(result); }
public static int B_RawLen(ILuaState lua) { LuaType t = lua.Type(1); lua.L_ArgCheck(t == LuaType.LUA_TTABLE || t == LuaType.LUA_TSTRING, 1, "table or string expected"); lua.PushInteger(lua.RawLen(1)); return(1); }
public void TypeTest04() { dynamic t = LuaType.GetType(typeof(int)); Type t1 = t; Type t2 = (Type)t; Assert.IsTrue(t1 == typeof(int)); Assert.IsTrue(t2 == typeof(int)); }
/// <summary> /// Creates the lua code variable table. /// </summary> /// <param name="dte">The DTE.</param> /// <param name="parent">The parent.</param> /// <param name="name">The name.</param> /// <param name="type">The type.</param> /// <param name="access">The access.</param> /// <param name="variable">The variable.</param> /// <returns></returns> public static LuaCodeVariable CreateLuaCodeVariableTable( DTE dte, CodeElement parent, string name, LuaType type, vsCMAccess access, TableConstructor variable) { var result = new LuaCodeVariableTable(dte, parent, name, access, variable); return(result); }
public string TypeName(LuaType t) { IntPtr ptr = LuaAPI.lua_typename(this.luaPtr, (int)t); if (ptr == IntPtr.Zero) { return(null); } return(LuaAPI.StringFromNativeUtf8(ptr, 0)); }
/// <summary> /// Creates the variable. /// </summary> /// <param name="dte">The DTE.</param> /// <param name="parent">The parent.</param> /// <param name="name">The name.</param> /// <param name="type">The type.</param> /// <param name="access">The access.</param> /// <param name="variable">The variable.</param> /// <returns></returns> public static LuaCodeVariable CreateVariable( DTE dte, CodeElement parent, string name, LuaType type, vsCMAccess access, Variable variable) { var result = new LuaCodeVariable(dte, parent, name, new LuaCodeTypeRef(dte, LuaDeclaredType.Find(type.ToString())), access, variable); return(result); }
public Form1(LuaType nType) { m_luaType = nType; InitializeComponent(); this.Text = CustomDefine.TOOL_TEXT[(int)m_luaType]; }
/// <summary> /// Returns the name of the type encoded by the value tp. /// </summary> /// <param name="state"> /// A <see cref="IntPtr"/> /// </param> /// <param name="tp"> /// A <see cref="LuaType"/> /// </param> /// <returns> /// A <see cref="System.String"/> /// </returns> public static extern string lua_typename( IntPtr state, LuaType tp );
public bool ConvertE2LByType(string sDirectory, string sFile, LuaType nType) { // analyze the name of excel file if (sFile.Length <= 0) { return false; } string strFullExcelName = sDirectory + "\\" + sFile; bool nReturn = false; LuaType nLuaType = CustomFunc.JudgeType(sFile); if (LuaType.Activity == nType) { if (nLuaType == nType) { nReturn = ConvertE2L_Activity(sDirectory, sFile); } } else if (LuaType.Packet == nType) { if (nLuaType == nType) { nReturn = ConvertE2L_Packet(sDirectory, sFile); } } else if (LuaType.Box == nType) { if (nLuaType == nType) { nReturn = ConvertE2L_Box(sDirectory, sFile); } } else { } return nReturn; }
/// <summary> /// Adds fields to the table object. /// </summary> /// <param name="variableName">Field variable name.</param> /// <param name="type">Field variable type.</param> /// <param name="variable">Optional. Field variable Node object.</param> /// <returns></returns> public CodeVariable AddInitVariable(string variableName, LuaType type, Variable variable) { var result = new LuaCodeVariable(DTE, parent, variableName, new LuaCodeTypeRef(DTE, LuaDeclaredType.Find(type.ToString())), vsCMAccess.vsCMAccessPublic, variable); AddInitVariable(result); return result; }
private void SetValue(LuaType luaType, object value) { Type = luaType; _value = value; }
public static void luaL_checktype(LuaState state, int argNum, LuaType type) { LuaNativeBinding.luaL_checktype(state, argNum, (int)type); }
internal static string TypeName( LuaType t ) { switch( t ) { case LuaType.LUA_TNIL: return "nil"; case LuaType.LUA_TBOOLEAN: return "boolean"; case LuaType.LUA_TLIGHTUSERDATA: return "userdata"; case LuaType.LUA_TUINT64: return "UInt64"; case LuaType.LUA_TNUMBER: return "number"; case LuaType.LUA_TSTRING: return "string"; case LuaType.LUA_TTABLE: return "table"; case LuaType.LUA_TFUNCTION: return "function"; case LuaType.LUA_TUSERDATA: return "userdata"; case LuaType.LUA_TTHREAD: return "thread"; case LuaType.LUA_TPROTO: return "proto"; case LuaType.LUA_TUPVAL: return "upval"; default: return "no value"; } }
string ILuaAPI.TypeName( LuaType t ) { return TypeName(t); }
public static string lua_typename(LuaState state, LuaType type) { IntPtr namePtr = LuaNativeBinding.lua_typename(state, (int)type); return Marshal.PtrToStringAnsi(namePtr); }
/// <summary> /// Returns the name of the type encoded by the value tp, which must be one the values returned by Type. /// </summary> public String TypeName(LuaType tp) { return Lua.lua_typename(NativeState, (int)tp); }
/// <summary> /// Checks whether the function argument arg has type t. /// </summary> public ILuaState CheckType(int arg, LuaType t) { Lua.luaL_checktype(NativeState, arg, (int)t); return this; }
/// <summary> /// Convert LUA_T<type> LuaType to its string value /// (like LuaType.LUA_TNIL to "LUA_TNIL") /// </summary> /// <param name="luaType"></param> /// <returns></returns> public static string LuaTypeToString(LuaType luaType) { return LuaTypeIntToString((int)luaType); }
/// <summary> /// Convert LuaType to int /// (like LuaType.LUA_TNONE to -1) /// </summary> /// <param name="luaType"></param> /// <returns></returns> public static int LuaTypeToInt(LuaType luaType) { return (int)luaType; }
private static bool IsEditableLuaType(LuaType type) { return (type == LuaType.LUA_TSTRING) || (type == LuaType.LUA_TBOOLEAN) || (type == LuaType.LUA_TNUMBER); }