當前位置: 首頁>>代碼示例>>C#>>正文


C# NLua.ObjectTranslator類代碼示例

本文整理匯總了C#中NLua.ObjectTranslator的典型用法代碼示例。如果您正苦於以下問題:C# ObjectTranslator類的具體用法?C# ObjectTranslator怎麽用?C# ObjectTranslator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ObjectTranslator類屬於NLua命名空間,在下文中一共展示了ObjectTranslator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CheckType

 public CheckType(ObjectTranslator translator)
 {
     this.translator = translator;
     extractValues.Add(GetExtractDictionaryKey(typeof(object)), new ExtractValue(GetAsObject));
     extractValues.Add(GetExtractDictionaryKey(typeof(sbyte)), new ExtractValue(GetAsSbyte));
     extractValues.Add(GetExtractDictionaryKey(typeof(byte)), new ExtractValue(GetAsByte));
     extractValues.Add(GetExtractDictionaryKey(typeof(short)), new ExtractValue(GetAsShort));
     extractValues.Add(GetExtractDictionaryKey(typeof(ushort)), new ExtractValue(GetAsUshort));
     extractValues.Add(GetExtractDictionaryKey(typeof(int)), new ExtractValue(GetAsInt));
     extractValues.Add(GetExtractDictionaryKey(typeof(uint)), new ExtractValue(GetAsUint));
     extractValues.Add(GetExtractDictionaryKey(typeof(long)), new ExtractValue(GetAsLong));
     extractValues.Add(GetExtractDictionaryKey(typeof(ulong)), new ExtractValue(GetAsUlong));
     extractValues.Add(GetExtractDictionaryKey(typeof(double)), new ExtractValue(GetAsDouble));
     extractValues.Add(GetExtractDictionaryKey(typeof(char)), new ExtractValue(GetAsChar));
     extractValues.Add(GetExtractDictionaryKey(typeof(float)), new ExtractValue(GetAsFloat));
     extractValues.Add(GetExtractDictionaryKey(typeof(decimal)), new ExtractValue(GetAsDecimal));
     extractValues.Add(GetExtractDictionaryKey(typeof(bool)), new ExtractValue(GetAsBoolean));
     extractValues.Add(GetExtractDictionaryKey(typeof(string)), new ExtractValue(GetAsString));
     extractValues.Add(GetExtractDictionaryKey(typeof(char[])), new ExtractValue (GetAsCharArray));
     extractValues.Add(GetExtractDictionaryKey(typeof(LuaFunction)), new ExtractValue(GetAsFunction));
     extractValues.Add(GetExtractDictionaryKey(typeof(LuaTable)), new ExtractValue(GetAsTable));
     extractValues.Add(GetExtractDictionaryKey(typeof(Dictionary<object,object>)), new ExtractValue(GetAsDictionary));
     extractValues.Add(GetExtractDictionaryKey(typeof(LuaUserData)), new ExtractValue(GetAsUserdata));
     extractNetObject = new ExtractValue (GetAsNetObject);
 }
開發者ID:JCH2k,項目名稱:NLua,代碼行數:25,代碼來源:CheckType.cs

示例2: MetaFunctions

		public MetaFunctions (ObjectTranslator translator)
		{
			this.translator = translator;
			gcFunction = new LuaNativeFunction (MetaFunctions.CollectObject);
			toStringFunction = new LuaNativeFunction (MetaFunctions.ToStringLua);
			indexFunction = new LuaNativeFunction (MetaFunctions.GetMethod);
			newindexFunction = new LuaNativeFunction (MetaFunctions.SetFieldOrProperty);
			baseIndexFunction = new LuaNativeFunction (MetaFunctions.GetBaseMethod);
			callConstructorFunction = new LuaNativeFunction (MetaFunctions.CallConstructor);
			classIndexFunction = new LuaNativeFunction (MetaFunctions.GetClassMethod);
			classNewindexFunction = new LuaNativeFunction (MetaFunctions.SetClassFieldOrProperty);
			execDelegateFunction = new LuaNativeFunction (MetaFunctions.RunFunctionDelegate);
		}
開發者ID:vontio,項目名稱:NLua,代碼行數:13,代碼來源:Metatables.cs

示例3: MetaFunctions

		public MetaFunctions (ObjectTranslator translator)
		{
			this.translator = translator;
			gcFunction = new LuaCore.lua_CFunction (MetaFunctions.collectObject);
			toStringFunction = new LuaCore.lua_CFunction (MetaFunctions.toString);
			indexFunction = new LuaCore.lua_CFunction (MetaFunctions.getMethod);
			newindexFunction = new LuaCore.lua_CFunction (MetaFunctions.setFieldOrProperty);
			baseIndexFunction = new LuaCore.lua_CFunction (MetaFunctions.getBaseMethod);
			callConstructorFunction = new LuaCore.lua_CFunction (MetaFunctions.callConstructor);
			classIndexFunction = new LuaCore.lua_CFunction (MetaFunctions.getClassMethod);
			classNewindexFunction = new LuaCore.lua_CFunction (MetaFunctions.setClassFieldOrProperty);
			execDelegateFunction = new LuaCore.lua_CFunction (MetaFunctions.runFunctionDelegate);
		}
開發者ID:Azhei,項目名稱:NLua,代碼行數:13,代碼來源:Metatables.cs

示例4: CheckType

 public CheckType(ObjectTranslator translator)
 {
     this.translator = translator;
     extractValues.Add (typeof(object).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsObject));
     extractValues.Add (typeof(sbyte).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsSbyte));
     extractValues.Add (typeof(byte).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsByte));
     extractValues.Add (typeof(short).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsShort));
     extractValues.Add (typeof(ushort).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsUshort));
     extractValues.Add (typeof(int).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsInt));
     extractValues.Add (typeof(uint).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsUint));
     extractValues.Add (typeof(long).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsLong));
     extractValues.Add (typeof(ulong).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsUlong));
     extractValues.Add (typeof(double).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsDouble));
     extractValues.Add (typeof(char).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsChar));
     extractValues.Add (typeof(float).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsFloat));
     extractValues.Add (typeof(decimal).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsDecimal));
     extractValues.Add (typeof(bool).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsBoolean));
     extractValues.Add (typeof(string).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsString));
     extractValues.Add (typeof(LuaFunction).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsFunction));
     extractValues.Add (typeof(LuaTable).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsTable));
     extractValues.Add (typeof(LuaUserData).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsUserdata));
     extractNetObject = new ExtractValue (getAsNetObject);
 }
開發者ID:CartBlanche,項目名稱:NLua,代碼行數:23,代碼來源:CheckType.cs

示例5: RunFunctionDelegate

		private static int RunFunctionDelegate (LuaState luaState, ObjectTranslator translator)
		{
			LuaNativeFunction func = (LuaNativeFunction)translator.GetRawNetObject (luaState, 1);
			LuaLib.LuaRemove (luaState, 1);
			return func (luaState);
		}
開發者ID:hanbim520,項目名稱:UFLua,代碼行數:6,代碼來源:Metatables.cs

示例6: MatchOperator

		static int MatchOperator (LuaState luaState, string operation, ObjectTranslator translator)
		{
			var validOperator = new MethodCache ();

			object target = GetTargetObject (luaState, operation, translator);

			if (target == null) {
				translator.ThrowError (luaState, "Cannot call " + operation + " on a nil object");
				LuaLib.LuaPushNil (luaState);
				return 1;
			}

			Type type = target.GetType ();
			var operators = type.GetMethods (operation, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

			foreach (var op in operators) {
				bool isOk = translator.MatchParameters (luaState, op, ref validOperator);

				if (!isOk)
					continue;

				object result;
				if (op.IsStatic)
					result = op.Invoke (null, validOperator.args);
				else
					result = op.Invoke (target, validOperator.args);
				translator.Push (luaState, result);
				return 1;
			}

			translator.ThrowError (luaState, "Cannot call (" + operation + ") on object type " + type.Name);
			LuaLib.LuaPushNil (luaState);
			return 1;
		}
開發者ID:hanbim520,項目名稱:UFLua,代碼行數:34,代碼來源:Metatables.cs

示例7: GetTargetObject

		static object GetTargetObject (LuaState luaState, string operation, ObjectTranslator translator)
		{
			Type t;
			object target = translator.GetRawNetObject (luaState, 1);
			if (target != null) {
				t = target.GetType ();
				if (t.HasMethod (operation))
					return target;
			}
			target = translator.GetRawNetObject (luaState, 2);
			if (target != null) {
				t = target.GetType ();
				if (t.HasMethod (operation))
					return target;
			}
			return null;
		}
開發者ID:hanbim520,項目名稱:UFLua,代碼行數:17,代碼來源:Metatables.cs

示例8: ClassGenerator

 public ClassGenerator(ObjectTranslator translator, Type klass)
 {
     this.translator = translator;
     this.klass = klass;
 }
開發者ID:Azhei,項目名稱:NLua,代碼行數:5,代碼來源:ClassGenerator.cs

示例9: Lua

		public Lua ()
		{
			luaState = LuaLib.luaL_newstate ();	// steffenj: Lua 5.1.1 API change (lua_open is gone)
			LuaLib.luaL_openlibs (luaState);		// steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here)
			LuaLib.lua_pushstring (luaState, "LUAINTERFACE LOADED");
			LuaLib.lua_pushboolean (luaState, true);
			LuaLib.lua_settable (luaState, (int)LuaIndexes.Registry);
			LuaLib.lua_newtable (luaState);
			LuaLib.lua_setglobal (luaState, "luanet");
			LuaLib.lua_pushvalue (luaState, (int)LuaIndexes.Globals);
			LuaLib.lua_getglobal (luaState, "luanet");
			LuaLib.lua_pushstring (luaState, "getmetatable");
			LuaLib.lua_getglobal (luaState, "getmetatable");
			LuaLib.lua_settable (luaState, -3);
			LuaLib.lua_replace (luaState, (int)LuaIndexes.Globals);
			translator = new ObjectTranslator (this, luaState);
			ObjectTranslatorPool.Instance.Add (luaState, translator);
			LuaLib.lua_replace (luaState, (int)LuaIndexes.Globals);
			LuaLib.luaL_dostring (luaState, Lua.init_luanet);	// steffenj: lua_dostring renamed to luaL_dostring

			// We need to keep this in a managed reference so the delegate doesn't get garbage collected
			panicCallback = new LuaCore.lua_CFunction (PanicCallback);
			LuaLib.lua_atpanic (luaState, panicCallback);
		}
開發者ID:Azhei,項目名稱:NLua,代碼行數:24,代碼來源:Lua.cs

示例10: MetaFunctions

		public MetaFunctions (ObjectTranslator translator)
		{
			this.translator = translator;
			GcFunction = new LuaNativeFunction (MetaFunctions.CollectObject);
			ToStringFunction = new LuaNativeFunction (MetaFunctions.ToStringLua);
			IndexFunction = new LuaNativeFunction (MetaFunctions.GetMethod);
			NewIndexFunction = new LuaNativeFunction (MetaFunctions.SetFieldOrProperty);
			BaseIndexFunction = new LuaNativeFunction (MetaFunctions.GetBaseMethod);
			CallConstructorFunction = new LuaNativeFunction (MetaFunctions.CallConstructor);
			ClassIndexFunction = new LuaNativeFunction (MetaFunctions.GetClassMethod);
			ClassNewindexFunction = new LuaNativeFunction (MetaFunctions.SetClassFieldOrProperty);
			ExecuteDelegateFunction = new LuaNativeFunction (MetaFunctions.RunFunctionDelegate);
			AddFunction = new LuaNativeFunction (MetaFunctions.AddLua);
			SubtractFunction = new LuaNativeFunction (MetaFunctions.SubtractLua);
			MultiplyFunction = new LuaNativeFunction (MetaFunctions.MultiplyLua);
			DivisionFunction = new LuaNativeFunction (MetaFunctions.DivideLua);
			ModulosFunction = new LuaNativeFunction (MetaFunctions.ModLua);
			UnaryNegationFunction = new LuaNativeFunction (MetaFunctions.UnaryNegationLua);
			EqualFunction = new LuaNativeFunction (MetaFunctions.EqualLua);
			LessThanFunction = new LuaNativeFunction (MetaFunctions.LessThanLua);
			LessThanOrEqualFunction = new LuaNativeFunction (MetaFunctions.LessThanOrEqualLua);
		}
開發者ID:hanbim520,項目名稱:UFLua,代碼行數:22,代碼來源:Metatables.cs

示例11: UnaryNegationLua

		static int UnaryNegationLua (LuaState luaState, ObjectTranslator translator)
		{
			object obj1 = translator.GetRawNetObject (luaState, 1);

			if (obj1 == null) {
				translator.ThrowError (luaState, "Cannot negate a nil object");
				LuaLib.LuaPushNil (luaState);
				return 1;
			}

			Type type = obj1.GetType ();
			MethodInfo opUnaryNegation = type.GetMethod ("op_UnaryNegation");

			if (opUnaryNegation == null) {
				translator.ThrowError (luaState, "Cannot negate object (" + type.Name + " does not overload the operator -)");
				LuaLib.LuaPushNil (luaState);
				return 1;
			}
			obj1 = opUnaryNegation.Invoke (obj1, new object [] { obj1 });
			translator.Push (luaState, obj1);
			return 1;
		}
開發者ID:hanbim520,項目名稱:UFLua,代碼行數:22,代碼來源:Metatables.cs

示例12: CollectObject

		private static int CollectObject (LuaState luaState, ObjectTranslator translator)
		{
			int udata = LuaLib.LuaNetRawNetObj (luaState, 1);

			if (udata != -1)
				translator.CollectObject (udata);

			return 0;
		}
開發者ID:hanbim520,項目名稱:UFLua,代碼行數:9,代碼來源:Metatables.cs

示例13: dumpStack

		/// <summary>
		/// Debug tool to dump the lua stack
		/// </summary>
		/// FIXME, move somewhere else
		public static void dumpStack (ObjectTranslator translator, LuaCore.lua_State luaState)
		{
			int depth = LuaLib.lua_gettop (luaState);
			Debug.WriteLine ("lua stack depth: " + depth);

			for (int i = 1; i <= depth; i++) {
				var type = LuaLib.lua_type (luaState, i);
				// we dump stacks when deep in calls, calling typename while the stack is in flux can fail sometimes, so manually check for key types
				string typestr = (type == LuaTypes.Table) ? "table" : LuaLib.lua_typename (luaState, type);
				string strrep = LuaLib.lua_tostring (luaState, i).ToString ();

				if (type == LuaTypes.UserData) {
					object obj = translator.getRawNetObject (luaState, i);
					strrep = obj.ToString ();
				}

#if WINDOWS_PHONE
                Debug.WriteLine("{0}: ({1}) {2}", i, typestr, strrep);
#elif !SILVERLIGHT
				Debug.Print ("{0}: ({1}) {2}", i, typestr, strrep);
#endif
			}
		}
開發者ID:Azhei,項目名稱:NLua,代碼行數:27,代碼來源:Metatables.cs

示例14: toString

		private static int toString (LuaCore.lua_State luaState, ObjectTranslator translator)
		{
			object obj = translator.getRawNetObject (luaState, 1);

			if (!obj.IsNull ())
				translator.push (luaState, obj.ToString () + ": " + obj.GetHashCode ());
			else
				LuaLib.lua_pushnil (luaState);

			return 1;
		}
開發者ID:Azhei,項目名稱:NLua,代碼行數:11,代碼來源:Metatables.cs

示例15: collectObject

		private static int collectObject (LuaCore.lua_State luaState, ObjectTranslator translator)
		{
			int udata = LuaLib.luanet_rawnetobj (luaState, 1);

			if (udata != -1)
				translator.collectObject (udata);

			return 0;
		}
開發者ID:Azhei,項目名稱:NLua,代碼行數:9,代碼來源:Metatables.cs


注:本文中的NLua.ObjectTranslator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。