Exemplo n.º 1
0
 public void assignData(NLua.LuaTable ele)
 {
     if (!data.Contains(ele))
     {
         data.Add(ele);
     }
 }
Exemplo n.º 2
0
 static public void assignGlobalData(LuaSaveCollection lsc, NLua.LuaTable data)
 {
     if (!lsc.data.Contains(data))
     {
         lsc.data.Add(data);
     }
 }
Exemplo n.º 3
0
        public void Move2D(NLua.LuaTable points)
        {
            var libNavigator = Utilities.GetReferenceOfPlugin("LibNavigator");

            // 'Convert.ToSingle' - okay, cast to 'float' - not okay
            libNavigator.GoPath(points.Values.Cast <NLua.LuaTable>().Select(l => new WowPoint(Convert.ToSingle(l["X"]), Convert.ToSingle(l["Y"]), Convert.ToSingle(l["Z"]))).ToArray(),
                                3f, info);
        }
Exemplo n.º 4
0
 public CozyLuaTable GetTable(string fullPath)
 {
     NLua.LuaTable table = mLua.GetTable(fullPath);
     if (table != null)
     {
         return(new CozyLuaTable(table));
     }
     return(null);
 }
Exemplo n.º 5
0
        public static Dictionary <string, string> LuaTableToDictionary(NLua.LuaTable data)
        {
            var r = new Dictionary <string, string>();

            foreach (KeyValuePair <object, object> de in data)
            {
                r[de.Key.ToString()] = de.Value.ToString();
            }
            return(r);
        }
Exemplo n.º 6
0
        public static List <object> LUATableToListUtility(Type t, NLua.LuaTable luat)
        {
            List <object> temp = new List <object>();

            foreach (var luaElement in luat.Values)
            {
                temp.Add(luaElement);
            }

            return(temp);
        }
Exemplo n.º 7
0
        public static List <string> LuaTableToList(NLua.LuaTable table, bool isShowKey)
        {
            var r = new List <string>();

            foreach (KeyValuePair <object, object> de in table)
            {
                var v = de.Value.ToString();
                if (isShowKey)
                {
                    v = $"{de.Key}.{v}";
                }
                r.Add(v);
            }
            return(r);
        }
Exemplo n.º 8
0
        List <string> LuaTableToList(NLua.LuaTable table, bool isShowKey)
        {
            var r = new List <string>();

            foreach (KeyValuePair <object, object> de in table)
            {
                var v = de.Value.ToString();
                if (isShowKey)
                {
                    v = de.Key.ToString() + @"." + v;
                }
                r.Add(v);
            }
            return(r);
        }
        public bool NLua(Parameter parameter)
        {
            using (NLua.Lua lua = new NLua.Lua())
            {
                StringBuilder statementBuilder = new StringBuilder()
                                                 .AppendLine("return {")
                                                 .AppendJoin("," + Environment.NewLine, parameter.Statements)
                                                 .AppendLine("}");

                NLua.LuaTable table = lua.DoString(statementBuilder.ToString())[0] as NLua.LuaTable;

                int[] results = table.Values.Cast <object>().Select(Convert.ToInt32).ToArray();

                return(Assert(results, parameter.Sum));
            }
        }
Exemplo n.º 10
0
        DataTable LuaTableToDataTable(NLua.LuaTable columns, NLua.LuaTable rows)
        {
            var d = new DataTable();

            if (columns == null)
            {
                return(d);
            }

            var ts = GetTypesFromRows(rows);

            var idx = 0;

            foreach (var column in columns.Values)
            {
                var name = column.ToString();
                if (ts == null)
                {
                    d.Columns.Add(name);
                }
                else
                {
                    d.Columns.Add(name, ts[idx++]);
                }
            }

            if (rows == null)
            {
                return(d);
            }
            var rowsKey = rows.Keys;

            foreach (var rowkey in rowsKey)
            {
                var row   = rows[rowkey] as NLua.LuaTable;
                var items = new List <object>();
                foreach (var item in row.Values)
                {
                    items.Add(item);
                }

                d.Rows.Add(items.ToArray());
            }
            return(d);
        }
Exemplo n.º 11
0
        //取应用目录
        public static NLua.LuaTable GetMemberInfo(NLua.LuaTable t, long g, long q, bool a)
        {
            // 当地时区
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));

            Sdk.Cqp.Model.GroupMemberInfo m = Common.CqApi.GetMemberInfo(g, q, a);
            t["Age"]          = m.Age;
            t["Area"]         = m.Area;
            t["Card"]         = m.Card;
            t["JoiningTime"]  = (long)(m.JoiningTime - startTime).TotalSeconds;
            t["LastDateTime"] = (long)(m.LastDateTime - startTime).TotalSeconds;
            t["Level"]        = m.Level;
            t["Nick"]         = m.Nick;
            t["PermitType"]   = (int)m.PermitType;
            t["Sex"]          = (int)m.Sex;
            t["SpecialTitle"] = m.SpecialTitle;
            return(t);
        }
Exemplo n.º 12
0
        List <Type> GetTypesFromRows(NLua.LuaTable rows)
        {
            if (rows == null)
            {
                return(null);
            }

            var ts = new List <Type>();

            foreach (var row in rows.Values)
            {
                foreach (var cell in (row as NLua.LuaTable).Values)
                {
                    ts.Add(cell.GetType());
                }
                return(ts);
            }
            return(null);
        }
Exemplo n.º 13
0
 public int Choice(string title, NLua.LuaTable choices) =>
 Choice(title, choices, false);
        public static void Test()
        {
            NLua.Lua state = new NLua.Lua();

            NLua.Lua state2 = new NLua.Lua();

            someData sd = new someData();

            sd.ID = 25;
            sd.sList.AddRange(new String[] { "this", " is", " a", " test", " list" });
            luaData ld = new luaData(sd);


            //var test = state.DoString("return 10 + 3*(5 + 2)")[0];
            //var type = test.GetType();

            //int value = 6;
            //state["test"] = value;
            //var result = state.DoString("return test*3+(test-3)")[0];

            //state.DoString(@"
            // function ScriptFunc (val1, val2)
            //     val1=val1+2
            //     val2=val2+3
            //     return val1, val2
            //  end");

            //var scriptFunc = state["ScriptFunc"] as NLua.LuaFunction;
            //var res = scriptFunc.Call(3, 5);

            testClass tc = new testClass("Some test string here");

            tc.list.Add(25);
            state["provision"] = "Random piece of information";



            testClass tc2 = new testClass("Indirect summon");

            tc2.data = ld;
            tc2.ProvideInfoToLua(state);
            //state["testObj"] = tc;

            state.LoadCLRPackage();
            // state.DoString(@" import ('The betrayer', 'TBAGW.Utilities')
            //   import ('System.Web')
            //    import ('System')");

            // var testStringFromObject = state.DoString("return TestObject.testList[0]")[0];
            // var elementType = testStringFromObject.GetType();
            // testClass testObjFromLUA = state.DoString("return TestObject")[0] as testClass;
            //bool bWhat = testObjFromLUA.GetType() == tc.GetType();

            state.DoString("print(\"Hello World\")");

            System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
            ofd.Filter           = "LUA files (*.lua)|*.lua";
            ofd.InitialDirectory = Game1.rootContent;
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                state = new NLua.Lua();
                state.LoadCLRPackage();
                state.DoFile(ofd.FileName);
                var time = System.IO.File.GetLastWriteTime(ofd.FileName);
            }
            //var statsTest = ((state["generateSomeStats"] as NLua.LuaFunction).Call()[0] as LuaStatEdit).ExtractStatChart();

            //BaseSprite bs = new BaseSprite();
            //bs.position = new Vector2(136, 2556);
            //if (Scenes.Editor.MapBuilder.loadedMap != null)
            //{
            //    bs.UpdatePosition();
            //}
            // List<List<Object>> luaStuff = new List<List<object>>();
            //var ttt = (state["save"] as NLua.LuaFunction).Call()[0].GetType();
            (state["save"] as NLua.LuaFunction).Call();
            var st = LuaSaveData.getGlobalData("My Collection", "luaStuff");

            (state["loadProcess"] as NLua.LuaFunction).Call();
            //var dabdab = ((state["getShapeData"] as NLua.LuaFunction).Call(bs));
            //  NLua.LuaFunction savedFunction = state["e1.Test"] as NLua.LuaFunction;
            uic = ((state["createUI"] as NLua.LuaFunction).Call()[0] as LuaUICollection).ConvertFromLua(state);
            goto skip;
            var luaRect = ShapeAnimation.animFromLuaInfo(((state["generateAnimation"] as NLua.LuaFunction).Call()[0] as LuaShapeAnimationInfo));
            var resldo  = (state["returnLuaSpecificData"] as NLua.LuaFunction).Call()[0];

            NLua.LuaTable lt = (state["returnLuaSpecificData"] as NLua.LuaFunction).Call()[0] as NLua.LuaTable;
            (state["GenerateSomeStuff"] as NLua.LuaFunction).Call();
            ListDataProvider.setLuaData(state);
            (state["publicStaticCall"] as NLua.LuaFunction).Call();
            (state["internalStaticCall"] as NLua.LuaFunction).Call();
            state["testObj"] = tc;
            var ele2                     = (state["attempt"] as NLua.LuaFunction).Call()[0];
            var returnedData             = (state["returnData"] as NLua.LuaFunction).Call()[0];
            var oldProvision             = state["provision"];
            var value2                   = state["testObj.i"];
            var function                 = state["MyFunc"] as NLua.LuaFunction;
            var funcRes                  = function.Call(state["testObj.i"])[0];
            var tableResult              = (state["returnTable"] as NLua.LuaFunction).Call()[0];
            var bCompare1                = tableResult.GetType() == typeof(NLua.LuaTable);
            var tableToList              = LUAUtilities.LUATableToListUtility(typeof(testClass), tableResult as NLua.LuaTable).Cast <testClass>().ToList();
            var tableToListGenericObject = LUAUtilities.LUATableToListUtility(typeof(testClass), tableResult as NLua.LuaTable);
            var listType                 = tableToList.GetType();
            var listTypeGO               = tableToListGenericObject.GetType();



            state = new NLua.Lua();
            state.LoadCLRPackage();
            state.DoFile(ofd.FileName);
            List <testClass> tcl = new List <testClass>();

            tcl.Add(new testClass(""));
            tcl.Last().i = 25;
            tcl.Add(new testClass(""));
            tcl.Last().i = 0;
            tcl.Add(new testClass(""));
            tcl.Last().i = 10;
            foreach (var item in tcl)
            {
                (state["setStuff"] as NLua.LuaFunction).Call(item);
            }

            tcl = LUAUtilities.LUATableToListUtility(typeof(testClass), (state["doStuff"] as NLua.LuaFunction).Call()[0] as NLua.LuaTable).Cast <testClass>().ToList();
            skip : { }
            bDoTest = false;
        }
Exemplo n.º 15
0
        public List <int> Choices(string title, NLua.LuaTable choices, bool isShowKey)
        {
            var list = LuaTableToList(choices, isShowKey);

            return(GetResultFromChoicesDialog(title, list.ToArray()));
        }
Exemplo n.º 16
0
 public List <int> Choices(string title, NLua.LuaTable choices) =>
 Choices(title, choices, false);
Exemplo n.º 17
0
        public string ShowData(string title, NLua.LuaTable columns, NLua.LuaTable rows, int defColumn)
        {
            var dt = LuaTableToDataTable(columns, rows);

            return(ShowDataGridDialog(title, dt, defColumn));
        }
Exemplo n.º 18
0
 public string ShowData(string title, NLua.LuaTable columns, NLua.LuaTable rows) =>
 ShowData(title, columns, rows, -1);
Exemplo n.º 19
0
        public int Choice(string title, NLua.LuaTable choices, bool isShowKey, int selected)
        {
            var list = global::Luna.Misc.Utils.LuaTableToList(choices, isShowKey);

            return(GetResultFromChoiceDialog(title, list.ToArray(), selected));
        }
Exemplo n.º 20
0
 public int Choice(string title, NLua.LuaTable choices, bool isShowKey) =>
 Choice(title, choices, isShowKey, -1);