예제 #1
0
파일: LuaRuntime.cs 프로젝트: viticm/pap2
        /// <summary>
        /// 获取lua虚拟机对象
        /// </summary>
        /// <returns>lua虚拟机对象</returns>
        public static LuaRuntime GetLuaRunTime()
        {
            if (luaRuntime == null)
            {
                luaRuntime = new LuaRuntime();                
                luaRuntime.Init();
            }

            return luaRuntime;
        }
예제 #2
0
        private void luaEditorControl1_queryObjects(object sender, luaEditor.QueryEventsArgs e)
        {
            string strOut = "";
            IntPtr ls_out = IntPtr.Zero;

            //参数规定:
            //szCode:   所有的代码
            //nPos:     光标位置(汉字按2个字符算)
            //nIsDelete 0为正常输入,1为删除,
            //  11-22为F1-F12,
            //  1111代表Ctrl+Shift+F1,
            //  1011代表Ctrl+F1
            //   111代表Shift+F1
            int nIsDelete = e.nPos > 0 ? 0 : 1;

            if (e.keyword != "")
            {
                nIsDelete = 10 + Int32.Parse(e.keyword);
            }

            bool bret = LuaRuntime.LuaRun("OnCodeSense", e.szCode, Math.Abs(e.nPos), nIsDelete, "true,1024,显示所有,1,false,语法检查", ref ls_out);

            strOut = Marshal.PtrToStringAnsi(ls_out);

            if (bret == false)
            {
                MessageBox.Show(strOut, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (strOut == null)
            {
                return;
            }

            string[] as_data = strOut.Split(new char[] { '|' });
            if (as_data.Length < 3)
            {
                MessageBox.Show("返回值不正确,返回值为:" + strOut, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // 读取overlen
            e.nOverLen = Int32.Parse((as_data[0]));

            // 初始化游标
            int nPosition = 3;

            // 读取list
            int nListCount = Int32.Parse((as_data[1]));

            if (as_data.Length < 3 + nListCount)
            {
                MessageBox.Show("List返回值个数不正确,返回值为:" + strOut, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            for (int i = 0; i < nListCount; i++)
            {
                string s_name = as_data[nPosition++] as string;
                string s_word = as_data[nPosition++] as string;
                string s_type = as_data[nPosition++] as string;
                string s_info = as_data[nPosition++] as string;
                e.leTable.Add(s_name, new luaEditor.leTableItem(s_name, s_type, s_word, s_info));
            }

            // 读取info
            int nInfoCount = Int32.Parse((as_data[2]));

            if (as_data.Length < 3 + nListCount + nInfoCount)
            {
                MessageBox.Show("Info返回值个数不正确,返回值为:" + strOut, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            for (int i = 0; i < nInfoCount; i++)
            {
                string s_text = as_data[nPosition++] as string;
                e.parms_list.Add(s_text.Replace("\n", "<BR>"));
            }
        }