private void DoLuaScript(string s)
 {
     lua = new Lua();
     //put in the persistant variables
     TFSH.ScriptVariables.PutVariables(lua);
     LuaRegistrationHelper.TaggedStaticMethods(lua, typeof(TFSH.PokeEngineScriptHelper));
     lua.DoString(s);
     //store any changes to the persistant variables
     TFSH.ScriptVariables.TakeVariables(lua);
 }
        public DebugConsole(Lua lua)
        {
            InitializeComponent();

            // Prepare Lua interpreter
            _lua = lua;
            LuaRegistrationHelper.TaggedStaticMethods(_lua, typeof(InspectionForm));

            // Keep the text-box in sync with the Log while the window is open
            HandleCreated   += delegate { Log.Handler += LogHandler; };
            HandleDestroyed += delegate { Log.Handler -= LogHandler; };
        }
Beispiel #3
0
 private void DoLuaScript(string s)
 {
     lua = new Lua();
     //put in the persistant variables
     TFSH.ScriptVariables.PutVariables(lua);
     //any variables that need to be included in the lua runtime go here
     lua["zone"] = world.currentArea;
     ///////
     LuaRegistrationHelper.TaggedStaticMethods(lua, typeof(TFSH.PokeEngineScriptHelper));
     lua.DoString(s);
     //store any changes to the persistant variables
     TFSH.ScriptVariables.TakeVariables(lua);
 }
Beispiel #4
0
 // called from Awake()...
 public void Init(string ScriptName)
 {
     this.ScriptName = ScriptName;
     if (L == null)               // we have one Lua state globally...
     {
         resourcePath      = Application.dataPath + "/Resources/";
         L                 = new Lua();
         L["package.path"] = resourcePath + "lua/?.lua";
         objects           = new Hashtable();
         L["objects"]      = objects;
     }
     LuaRegistrationHelper.TaggedInstanceMethods(L, this);
     Reload();
 }
Beispiel #5
0
 [TestMethod] public void BigTable()
 {
     using (var lua = new Lua())
     {
         LuaRegistrationHelper.TaggedStaticMethods(lua, this.GetType());
         lua["lua"] = lua;
         lua.DoString("a = MakeBigTable(1, lua)");
         lua.DoString("b = MakeBigTable(256, lua)");
         lua.DoString("ConsumeBigTable(b)");
         lua.DoString("c = MakeBigTable(65536, lua)");
         lua.DoString("ConsumeBigTable(a)");
         lua.DoString("ConsumeBigTable(c)");
     }
 }
Beispiel #6
0
        private void useMove(BattlePosition position)
        {
            //show dialog message
            PokeEngineScriptHelper.ShowMessage(position.pokemon.pokemon.Nickname + " uses " + position.choice.move.bMove.name);
            //use the move
            Lua lua = new Lua();

            //put in the persistant variables
            TFSH.ScriptVariables.PutVariables(lua);
            lua["user"]   = position.pokemon;
            lua["move"]   = position.choice.move;
            lua["effect"] = position.choice.move.bMove.effectScript;
            lua["target"] = position.choice.target.pokemon;
            LuaRegistrationHelper.TaggedStaticMethods(lua, typeof(TFSH.PokeEngineScriptHelper));
            lua.DoString(position.choice.move.bMove.moveScript);
            //store any changes to the persistant variables
            TFSH.ScriptVariables.TakeVariables(lua);
        }
Beispiel #7
0
    public static LuaState CreateLuaState()
    {
        _luaState = new LuaState();
        LuaRegistrationHelper.TaggedStaticMethods(_luaState, typeof(Lua));

#if _DEBUG_
        _luaState["_DEBUG_"] = true;
#endif
#if _MOCK_
        _luaState["_MOCK_"] = true;
#endif
#if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
        _luaState["_MOBILE_PLATFORM_"] = true;
#endif

        // 初始化 Lua 环境,对接 Unity 到 Lua
        RequireLua("defs");

        return(_luaState);
    }
Beispiel #8
0
        public virtual Lua NewLua()
        {
            var lua = new Lua();

            LuaRegistrationHelper.TaggedStaticMethods(lua, typeof(Log));
            LuaRegistrationHelper.TaggedStaticMethods(lua, typeof(StringUtils));
            LuaRegistrationHelper.TaggedStaticMethods(lua, typeof(MathUtils));
            LuaRegistrationHelper.TaggedStaticMethods(lua, typeof(RandomUtils));
            LuaRegistrationHelper.TaggedStaticMethods(lua, typeof(ColorUtils));

            lua["temp"] = Path.GetTempPath() + Path.DirectorySeparatorChar;
            lua["Pi"]   = Math.PI;

            lua["Game"]   = this;
            lua["Engine"] = Engine;

            // Import .NET constructors
            ImportConstructor(lua, typeof(Point));
            ImportConstructor(lua, typeof(Size));
            ImportConstructor(lua, typeof(Rectangle));
            ImportConstructor(lua, typeof(Color3));
            ImportConstructor(lua, typeof(Color4));
            ImportConstructor(lua, typeof(Half2));
            ImportConstructor(lua, typeof(Half3));
            ImportConstructor(lua, typeof(Half4));
            ImportConstructor(lua, typeof(Vector2));
            ImportConstructor(lua, typeof(Vector3));
            ImportConstructor(lua, typeof(Vector4));
            ImportConstructor(lua, typeof(Quaternion));
            ImportConstructor(lua, typeof(Rational));
            ImportConstructor(lua, typeof(Vector2Ray));
            ImportConstructor(lua, typeof(DoubleVector3));
            ImportConstructor(lua, typeof(XColor));

            LuaRegistrationHelper.TaggedInstanceMethods(lua, this);
            LuaRegistrationHelper.TaggedStaticMethods(lua, typeof(GameBase));

            return(lua);
        }
Beispiel #9
0
        public override Lua NewLua()
        {
            var lua = base.NewLua();

            LuaRegistrationHelper.Enumeration <GameState>(lua);

            // Make methods globally accessible (without prepending the class name)
            LuaRegistrationHelper.TaggedStaticMethods(lua, typeof(Program));
            LuaRegistrationHelper.TaggedStaticMethods(lua, typeof(Settings));
            LuaRegistrationHelper.TaggedInstanceMethods(lua, GuiManager);

            lua["Settings"]  = Settings.Current;
            lua["State"]     = CurrentState;
            lua["Session"]   = CurrentSession;
            lua["Presenter"] = CurrentPresenter;
            lua["Universe"]  = CurrentPresenter.Universe;

            // Boolean flag to indicate if the game is running a mod
            lua["IsMod"] = (ContentManager.ModDir != null);

            return(lua);
        }
Beispiel #10
0
        [TestMethod] public void Enumeration()
        {
            using (var lua = new Lua())
            {
                lua.DoString(
                    @"function test1(table)
						assert(table.A == 0)
						assert(table.B == 1)
						assert(table.C == 2)
						assert(table.D == 3)
						assert_count(table, 4)
					end
					function assert_count(table, expected_count)
						local count = 0
						for k in pairs(table) do count = count + 1 end
						assert(count == expected_count)
					end
				"                );
                LuaRegistrationHelper.Enumeration <Enumeration_Target1>(lua);
                using (var table = LuaRegistrationHelper.NewEnumeration <Enumeration_Target1>(lua))
                    lua["Target1"] = table;
                lua.DoString("test1(Enumeration_Target1); test1(Target1)");

                lua.DoString(
                    @"function test2(table)
						assert(table.A == 5)
						assert(table.S == 6)
						assert(table.D == 7)
						assert(table.F == 8)
						assert_count(table, 4)
					end
				"                );
                LuaRegistrationHelper.Enumeration <Enumeration_Target2>(lua);
                using (var table = LuaRegistrationHelper.NewEnumeration <Enumeration_Target2>(lua))
                    lua["Target2"] = table;
                lua.DoString("test2(Enumeration_Target2); test2(Target2)");
            }
        }
        public DialogRenderer(GuiManager manager, Dialog dialog, Point location = new Point(), Lua lua = null)
        {
            _manager     = manager;
            DialogModel  = dialog;
            DialogRender = dialog.GenerateRender(_manager.DialogManager);
            _location    = location;
            _lua         = lua;

            LayoutHelper();
            _manager.DialogManager.Engine.DeviceReset += LayoutHelper;

            if (lua != null)
            {
                #region Register Lua variables and functions
                // Register all controls as direct variables when possible
                foreach (var control in dialog.Controls)
                {
                    if (!string.IsNullOrEmpty(control.Name))
                    {
                        try
                        {
                            _lua[control.Name] = control;
                        }
                        catch (LuaException)
                        {}
                    }
                }

                _lua["Me"] = this;

                LuaRegistrationHelper.Enumeration <Render.MsgBoxType>(_lua);
                LuaRegistrationHelper.Enumeration <Render.MsgBoxResult>(_lua);
                #endregion

                dialog.ScriptFired += LuaExecute;
            }
        }
Beispiel #12
0
 public static void Register(Lua L)
 {
     L.NewTable("utils");
     LuaRegistrationHelper.TaggedStaticMethods(L, typeof(MyClass));
 }
 public void RegisterObject(object obj)
 {
     LuaRegistrationHelper.TaggedInstanceMethods(Lua, obj);
 }
Beispiel #14
0
 public static void Register(Lua lua)
 {
     lua.NewTable("Util");
     LuaRegistrationHelper.TaggedStaticMethods(lua, typeof(TaggedStaticMethods_Target));
 }
Beispiel #15
0
 public void Register(Lua lua)
 {
     lua.NewTable("Util");
     LuaRegistrationHelper.TaggedInstanceMethods(lua, this);
 }