Example #1
0
        public CardCollect Run(CardCollect cc)
        {
            CozyLuaCore lua = new CozyLuaCore();

            lua.LoadCLRPackage();
            lua.DoString("import ('CozyPoker.Engine', 'CozyPoker.Engine.Model')");
            lua.DoString("import ('CozyPoker.Engine', 'CozyPoker.Engine.Util')");
            lua.DoFile(PathTransform.LuaScript(script_));
            var f = lua.GetFunction("deal");

            return((CardCollect)f.Call(cc).First());
        }
Example #2
0
        public void Run(CardCollect cc)
        {
            CozyLuaCore lua = new CozyLuaCore();

            lua.LoadCLRPackage();
            lua.DoString("import ('CozyPoker.Engine', 'CozyPoker.Engine.Model')");
            lua.DoString("import ('CozyPoker.Engine', 'CozyPoker.Engine.Util')");
            lua.DoFile(PathTransform.LuaScript(script_));
            var f = lua.GetFunction("shuffle");

            f.Call(cc);
        }
Example #3
0
        public CardCollect Run()
        {
            CozyLuaCore lua = new CozyLuaCore();

            lua.LoadCLRPackage();
            lua.DoString("import ('CozyPoker.Engine', 'CozyPoker.Engine.Model')");
            lua.DoString("import ('CozyPoker.Engine', 'CozyPoker.Engine.Util')");
            lua.DoFile(PathTransform.LuaScript(script_));
            //lua.DoString(@" import ('CozyPoker.Engine', 'CozyPoker.Engine.Model')");
            //lua.DoString(@"
            //    cc = CardCollect()
            //    c = Card(1,1)
            //    cc:Add(c)");
            return((CardCollect)lua["cc"]);
        }
Example #4
0
        virtual public bool Init(string script)
        {
            CozyLuaCore lua = new CozyLuaCore();

            lua.DoFile(PathTransform.LuaScript(script));
            mapMethod = new Dictionary <string, string>();
            var methods = lua.GetTable("methods");
            var em      = methods.GetEnumerator();

            while (em.MoveNext())
            {
                mapMethod.Add((string)em.Key, (string)em.Value);
            }
            return(true);
        }
Example #5
0
        static void Main(string[] args)
        {
            CozyLuaCore lua = new CozyLuaCore();

            var r = (double)lua.DoString("return 10 + 3*(5 + 2)")[0];

            Console.WriteLine(r);

            lua["x"] = 12.0;
            Console.WriteLine(lua["x"]);

            var r2 = (double)lua.DoString("return 10 + x*(5 + 2)")[0];

            Console.WriteLine(r2);

            lua.DoString(@"
                function ScriptFunc (val1, val2)
                    if val1 > val2 then
                        return val1 + 1
                    else
                        return val2 - 1
                    end
                end");

            var scriptFunc = lua.GetFunction("ScriptFunc");
            var r3         = (double)scriptFunc.Call(3, 5).First();

            Console.WriteLine(r3);

            lua.DoString(@"
                tablex = {
                    x=1,
                    y='hehe'
                }");
            var tablex = lua.GetTable("tablex");

            foreach (var i1 in tablex.Keys)
            {
                Console.WriteLine(i1);
            }
            var i2 = tablex.GetEnumerator();

            while (i2.MoveNext())
            {
                Console.WriteLine(i2.Value);
            }

            Program p = new Program();

            lua.RegisterFunction("tf", p, typeof(Program).GetMethod("TestFunc"));
            var r4 = (int)(double)lua.DoString("return tf(1,2)")[0];

            Console.WriteLine(r4);

            lua.RegisterFunction(
                "p",
                typeof(System.Console).GetMethod(
                    "WriteLine",
                    new Type[] { typeof(String) })
                );
            lua.DoString("p('hello')");
        }
Example #6
0
File: LuaExt.cs Project: sgww/cozy
        public static void InitEnvironment(this CozyLuaCore lua)
        {
            lua.LoadCLRPackage();

            lua.DoFile(PathTransform.LuaScript("init"));
        }