예제 #1
0
        /// <summary>
        /// Creates a new Lua environment and registers various classes and functions from the game to it.
        /// </summary>
        public void initializeLua()
        {
            global = compiler.CreateEnvironment();
            game = new LuaTable();
            global["Game"] = game;

            global["Log"] = new Action<string>(Logger.Log);

            global["GAME_DIR"] = GAME_DIR_DEFAULT;
            //TODO: make this load from some kind of config file and only fail to this default

            global["runFile"] = new Action<string, LuaTable>(runLuaFile);

            
            LuaTable loadingInterface = new LuaTable();
            loadingInterface["display"] = new Action<string>(Screens.LoadingScreen.Display);
            loadingInterface["change"] = new Action<string>(Screens.LoadingScreen.ChangeMessage);
            game["LoadingScreen"] = loadingInterface;

            game["loadVoxtures"] = new Func<string, LuaTable>(loadVoxtures);

            LuaType.RegisterTypeAlias("material", typeof(OutpostLibrary.Content.Material));
            LuaTable mat = new LuaTable();
            game["Material"] = LuaType.GetType(typeof(OutpostLibrary.Content.Material));
            game["Transparency"] = LuaType.GetType(typeof(OutpostLibrary.Content.Transparency));
            game["Solidity"] = LuaType.GetType(typeof(OutpostLibrary.Content.Solidity));
            //TODO: solidity should be a lua-side thing

            game["Sizes"] = LuaType.GetType(typeof(OutpostLibrary.Navigation.Sizes));
            game["Directions"] = LuaType.GetType(typeof(OutpostLibrary.Navigation.Directions));

            game["map"] = MainGame.mainGame;
            //TODO: this clearly needs reworked
            

            global["twoDArray"] = new Func<int, LuaTable[,]>(delegate(int size) { return new LuaTable[size, size]; });
            global["threeDArray"] = new Func<int, LuaTable[, ,]>(delegate(int size) { return new LuaTable[size, size, size]; });

            LuaType.RegisterTypeAlias("IntVector3", typeof(OutpostLibrary.IntVector3));
            global["IntVector3"] = LuaType.GetType(typeof(OutpostLibrary.IntVector3));

            LuaType.RegisterTypeAlias("Vector3", typeof(Microsoft.Xna.Framework.Vector3));
            global["Vector3"] = LuaType.GetType(typeof(Microsoft.Xna.Framework.Vector3));

            LuaType.RegisterTypeAlias("Chunk", typeof(Chunk));
            global["Chunk"] = LuaType.GetType(typeof(Chunk));

            LuaType.RegisterTypeAlias("SolidBlock", typeof(Blocks.SolidBlock));
            global["SolidBlock"] = LuaType.GetType(typeof(Blocks.SolidBlock));

            LuaType.RegisterTypeAlias("Structure", typeof(MapStructure));
            global["Structure"] = LuaType.GetType(typeof(MapStructure));

            //global["Double"] = LuaType.GetType(typeof(Double));
            
            runLuaFile("init.lua");
        }
예제 #2
0
파일: Program.cs 프로젝트: edisonh/neolua
		private static void TestDynamic()
		{
			var lua = new Lua();
			var global = new LuaGlobalPortable(lua) { ["workspace"] = new DynData() };

			var r = global.DoChunk("return workspace.Part", "Test.lua");

			Console.WriteLine(r.ToString());
		}
예제 #3
0
파일: LuaTable.cs 프로젝트: edisonh/neolua
		public void TestMember10()
		{
			LuaGlobalPortable g = new LuaGlobalPortable(new Lua());
			g["a"] = 1;
			g.Members.Clear();

			TestResult(new LuaResult(g["a"]), new object[] { null });
		}