当前位置: 首页>>代码示例>>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;未经允许,请勿转载。