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


C# ObjectTranslator.Push方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: ToStringLua

		private static int ToStringLua (LuaState luaState, ObjectTranslator translator)
		{
			object obj = translator.GetRawNetObject (luaState, 1);

			if (obj != null)
				translator.Push (luaState, obj.ToString () + ": " + obj.GetHashCode ().ToString());
			else
				LuaLib.LuaPushNil (luaState);

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

示例4: AddLua

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

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

			Type type = obj1.GetType ();
			MethodInfo opAddition = type.GetMethod ("op_Addition");

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


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