Beispiel #1
0
        public LuaGame(string entryPath)
        {
            Window.Title = "Bubble Engine";
            //create lua state
            state = new BubbleLua(new Lua());
            state.Lua.LoadCLRPackage();
            state.Bubble ["runtime"] = new LuaAPI.Runtime();
            state.Bubble ["fonts"]   = new LuaAPI.Fonts(FontContext);
            luaGraphics = new LuaAPI.Graphics(null, this);
            state.Bubble ["graphics"] = luaGraphics;
            state.Bubble ["window"]   = new LuaAPI.LWindow(Window);
            LuaAPI.Util.RegisterEnum(typeof(Keys), state);
            state.Lua ["embedres"] = new LuaAPI.EmbeddedLoader();
            //run init scripts
            state.Lua.DoString(EmbeddedResources.GetString("BubbleEngine.LuaAPI.procure.lua"));
            state.Lua.DoString(EmbeddedResources.GetString("BubbleEngine.LuaAPI.init.lua"));
            //config
            state.Lua.DoFile(entryPath);
            gameTable = (LuaTable)state.Lua ["game"];
            var cfg = (LuaFunction)gameTable ["config"];

            if (cfg == null)
            {
                throw new NLua.Exceptions.LuaScriptException("Script must have a game.config() function", entryPath);
            }
            cfg.Call();
            updateFunction = (LuaFunction)gameTable ["update"];
            drawFunction   = (LuaFunction)gameTable ["draw"];
        }
Beispiel #2
0
 public LuaGame(string entryPath)
 {
     Window.Title = "Bubble Engine";
     //create lua state
     state = new BubbleLua (new Lua());
     state.Lua.LoadCLRPackage ();
     state.Bubble ["runtime"] = new LuaAPI.Runtime();
     state.Bubble ["fonts"] = new LuaAPI.Fonts (FontContext);
     luaGraphics = new LuaAPI.Graphics (null, this);
     state.Bubble ["graphics"] = luaGraphics;
     state.Bubble ["window"] = new LuaAPI.LWindow (Window);
     LuaAPI.Util.RegisterEnum (typeof(Keys), state);
     state.Lua ["embedres"] = new LuaAPI.EmbeddedLoader ();
     //run init scripts
     state.Lua.DoString(EmbeddedResources.GetString("BubbleEngine.LuaAPI.procure.lua"));
     state.Lua.DoString(EmbeddedResources.GetString("BubbleEngine.LuaAPI.init.lua"));
     //config
     state.Lua.DoFile(entryPath);
     gameTable = (LuaTable)state.Lua ["game"];
     var cfg = (LuaFunction)gameTable ["config"];
     if (cfg == null) {
         throw new NLua.Exceptions.LuaScriptException ("Script must have a game.config() function", entryPath);
     }
     cfg.Call ();
     updateFunction = (LuaFunction)gameTable ["update"];
     drawFunction = (LuaFunction)gameTable ["draw"];
 }