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


C# NLua.Lua類代碼示例

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


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

示例1: ScriptManager

 public ScriptManager()
 {
     _scriptQueue = new Queue<Tuple<string, Entity, string>>();
     _lua = new Lua();
     SandboxVM();
     RegisterScriptMethods();
 }
開發者ID:zunath,項目名稱:MMXEngine,代碼行數:7,代碼來源:ScriptManager.cs

示例2: LuaScriptContext

 public LuaScriptContext()
 {
     Log.Write("debug", "Creating Lua script context");
     Lua = new Lua();
     Lua.HookException += OnLuaException;
     functionCache = new Cache<string, LuaFunction>(Lua.GetFunction);
 }
開發者ID:Generalcamo,項目名稱:OpenRA,代碼行數:7,代碼來源:LuaScriptContext.cs

示例3: Main

        private static void Main()
        {
            Console.Title = "NLua Test Environment";

            object x = 3;
            double y = (double)(int)x;

            string script = "function add(a, b) return a + b, a, b; end\n" +
                            "local function sub(a, b) return a - b; end\n" +
                            "local function mul(a, b) return a * b; end\n" +
                            "local function div(a, b) return a / b; end\n" +
                            "print(\"Adding 1 and 5 gives us \" .. add(1, 5));\n" +
                            "print(\"Subtracting 8 and 2 gives us \" .. sub(8, 2));\n" +
                            "print(\"Multiplying 32 and 1024 gives us \" .. mul(32, 1024));\n" +
                            "print(\"Dividing 8 and 2 gives us \" .. div(8, 2));\n";

            using (dynamic lua = new Lua())
            {
                lua.LoadStandardLibrary(LuaStandardLibraries.Basic);
                lua.DoString("print(\"This confirms the Lua environment has loaded the basic standard library.\\nThe Lua environment is operational.\");");
                lua.DoFile("TestScript.lua");

                lua.v = "test";

                object[] table = lua.x;
            }

            Console.ReadLine();
        }
開發者ID:JumpNotZero,項目名稱:NLua,代碼行數:29,代碼來源:Program.cs

示例4: Spell

        public Spell(XmlNode xml, Lua lua)
            : base()
        {
            Name = xml.SelectSingleNode("name").InnerText;
            Desc = xml.SelectSingleNode("desc").InnerText;

            Type = (AttackType)Enum.Parse(typeof(AttackType), xml.SelectSingleNode("type").InnerText);
            Target = (BattleTarget)Enum.Parse(typeof(BattleTarget), xml.SelectSingleNode("target").InnerText);

            XmlNode targetsFirstNode = xml.SelectSingleNode("targetEnemiesFirst");
            TargetEnemiesFirst = targetsFirstNode == null ? true : Boolean.Parse(targetsFirstNode.InnerText);

            XmlNode costNode = xml.SelectSingleNode("cost");
            MPCost = costNode == null ? 0 : Int32.Parse(costNode.InnerText);

            XmlNode orderNode = xml.SelectSingleNode("order");
            Order = orderNode == null ? 0 : Int32.Parse(orderNode.InnerText);

            Elements = GetElements(xml.SelectNodes("elements/element")).ToArray();
            Statuses = GetStatusChanges(xml.SelectNodes("statusChange")).ToArray();

            Power = Int32.Parse(xml.SelectSingleNode("power").InnerText);
            Hitp = Int32.Parse(xml.SelectSingleNode("hitp").InnerText);

            XmlNode hitsNode = xml.SelectSingleNode("hits");
            Hits = hitsNode == null ? 1 : Int32.Parse(hitsNode.InnerText);

            DamageFormula = GetFormula(xml.SelectSingleNode("formula"), lua);
            HitFormula = GetHitFormula(xml.SelectSingleNode("hitFormula"), lua);
        }
開發者ID:skinitimski,項目名稱:Reverence,代碼行數:30,代碼來源:Spell.cs

示例5: Awakening

        public bool Awakening()
        {
            spaar.ModLoader.Game.OnSimulationToggle += GameOnOnSimulationToggle;
            spaar.ModLoader.Game.OnLevelWon += GameOnOnLevelWon;
            env = new NLua.Lua();
            env.LoadCLRPackage();
            env["this"] = this; // Give the script access to the gameobject.
            env["transform"] = transform;
            env["gameObject"] = gameObject;
            env["enabled"] = enabled;
            env["useAPI"] = new Action(UseAPI);
            env["disableAPI"] = new Action(DisableAPI);

            if (Settings.useAPI)
            {
                Besiege.SetUp();
                env["besiege"] = Besiege._besiege;
            }
            try
            {
                env.DoString(source);
            }
            catch (NLua.Exceptions.LuaException e)
            {
                Debug.LogError(FormatException(e), context: gameObject);
                return false;
            }
            Call("Awake");
            return true;
        }
開發者ID:L3tum,項目名稱:BesiegeScriptingMod,代碼行數:30,代碼來源:LuaBehaviour.cs

示例6: TestBinaryLoadFile

		public void TestBinaryLoadFile ()
		{
			using (Lua lua = new Lua ()) {
				lua.LoadCLRPackage ();
				if (IntPtr.Size == 4)
					lua.DoFile ("test_32.luac");
				else
					lua.DoFile ("test_64.luac");

				int width = (int)(double)lua ["width"];
				int height = (int)(double)lua ["height"];
				string message = (string)lua ["message"];
				int color_g	= (int)(double)lua ["color.g"];
				LuaFunction func = (LuaFunction)lua ["func"];
				object[] res = func.Call (12, 34);
				int x = (int)(double)res [0];
				int y = (int)(double)res [1];
				//function func(x,y)
				//	return x,x+y
				//end

				Assert.AreEqual (100, width);
				Assert.AreEqual (200, height);
				Assert.AreEqual ("Hello World!", message);
				Assert.AreEqual (20, color_g);
				Assert.AreEqual (12, x);
				Assert.AreEqual (46, y);
			}
		}
開發者ID:mMellowz,項目名稱:revcore,代碼行數:29,代碼來源:LoadFileTests.cs

示例7: Start

	void Start()
	{
		lua = new NLua.Lua();
		lua.LoadCLRPackage();
		var method = typeof(Debug).GetMethod("Log", new Type[] { typeof(object) });
		lua.RegisterFunction("print", method);
	}
開發者ID:wuzhangwuzhang,項目名稱:BWM,代碼行數:7,代碼來源:LuaTest.cs

示例8: Init

        public void Init()
        {
            if (IsInitialized)
                throw new InvalidOperationException("Already Initialized!");

            if (_state != null) _state.Dispose();
            
            _state = new Lua();
            _state.LoadCLRPackage();

            _state.DoString(@"luanet.load_assembly('WGestures.Core');
                              luanet.load_assembly('WindowsInput');
                              luanet.load_assembly('WGestures.Common');

                              GestureModifier=luanet.import_type('WGestures.Core.GestureModifier');  
                              VK=luanet.import_type('WindowsInput.Native.VirtualKeyCode');
                              Native=luanet.import_type('WGestures.Common.OsSpecific.Windows.Native');
                            ", "_init");

            _state["Input"] = Sim.Simulator;
            _state.RegisterFunction("ReportStatus", this, typeof(ScriptCommand).GetMethod("OnReportStatus"));

            if(InitScript != null)
            {
                DoString(InitScript, "Init");
            }
            
            IsInitialized = true;
        }
開發者ID:huipengly,項目名稱:WGestures,代碼行數:29,代碼來源:ScriptCommand.cs

示例9: ScriptComponent

        public ScriptComponent()
        {
            Family = ComponentFamily.Script;

            lua = new Lua();
            lua.LoadCLRPackage();
        }
開發者ID:MSylvia,項目名稱:space-station-14,代碼行數:7,代碼來源:Script.cs

示例10: InitEditorState

        private static void InitEditorState(Lua state)
        {
            state.LoadCLRPackage();

            string resName = "WorldSmith.Scripts.WorldsmithImports.lua";

            Assembly asm = Assembly.GetExecutingAssembly();
            using (System.IO.Stream s = asm.GetManifestResourceStream(resName))
            using (System.IO.StreamReader reader = new System.IO.StreamReader(s))
            {
                string data = reader.ReadToEnd();

                state.DoString(data, resName);               
            }

            state["Units"] = DotaData.AllUnits;          
            state["Heroes"] = DotaData.AllHeroes;          
            state["Abilities"] = DotaData.AllAbilities;           
            state["Items"] = DotaData.DefaultItems;
            state["Events"] = DotaData.Events;

            //Bind the DataClass enum
            state.DoString("DataClass = {}");
            state["DataClass.Default"] = DotaDataObject.DataObjectInfo.ObjectDataClass.Default;
            state["DataClass.Override"] = DotaDataObject.DataObjectInfo.ObjectDataClass.Override;
            state["DataClass.Custom"] = DotaDataObject.DataObjectInfo.ObjectDataClass.Custom;


        }
開發者ID:Oplkill,項目名稱:WorldSmith,代碼行數:29,代碼來源:LuaHelper.cs

示例11: RegisterNLuaBox

        public static void RegisterNLuaBox(Lua context)
        {
            context.RegisterLuaDelegateType (typeof (EventHandler<EventArgs>), typeof (LuaEventArgsHandler));
            context.RegisterLuaDelegateType (typeof (EventHandler), typeof (LuaEventArgsHandler));
            context.RegisterLuaDelegateType (typeof (EventHandler<UIButtonEventArgs>), typeof (LuaButtonEventArgsHandler));

            context.RegisterLuaClassType (typeof (UIViewController), typeof (NLuaBoxUIViewControllerBinder));
        }
開發者ID:kumpera,項目名稱:NLuaBox,代碼行數:8,代碼來源:NLuaBoxBinder.cs

示例12: Main

 static void Main(string [] args)
 {
     using (var l = new Lua ()) {
         Action c = () => { Console.WriteLine ("Ola"); };
         l ["d"] = c;
         l.DoString (" d () ");
     }
 }
開發者ID:The-Megax,項目名稱:NLua,代碼行數:8,代碼來源:Program.cs

示例13: BuildingManager

 static BuildingManager()
 {
     lua = new Lua();
     InitPaths = new Dictionary<string,string>();
     Buildings = new List<Building>();
     //Scan();
     //lua.
 }
開發者ID:noogai03sprojects,項目名稱:AerialArchitect,代碼行數:8,代碼來源:BuildingManager.cs

示例14: VsErcPackage

 public VsErcPackage()
 {
     instance = this;
     this.vsHelper = new VsHelper(this);
     this.vsErcLogger = new VsErcLogger(this);
     this.lua = new Lua();
     this.vsErcBindings = new VsErcBindings(this, VsErcBindings.DefaultErcFilePath);
 }
開發者ID:prabirshrestha,項目名稱:vs-erc,代碼行數:8,代碼來源:VsErcPackage.cs

示例15: SetLog

		public static void SetLog(Lua lua)
		{
			if (PrintFunction == null)
				PrintFunction = new LuaNativeFunction(PrintWarning);
			
			LuaLib.LuaPushStdCallCFunction(lua.LuaState, PrintFunction);
			LuaLib.LuaSetGlobal(lua.LuaState, "log");
		}
開發者ID:SD-J,項目名稱:UnityLua,代碼行數:8,代碼來源:UnityExpand.cs


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