コード例 #1
0
        public void WriteHelp(String strCmd)
        {
            LuaFuncDescriptor pDesc = (LuaFuncDescriptor)PackageFuncs[strCmd];

            Console.WriteLine(pDesc.getFuncFullDoc());
            return;
        }
コード例 #2
0
ファイル: lau.cs プロジェクト: TheMuffinGroup/BobsPoopTools
        public static void registerLuaFunctions(String strPackage, Object pTarget, String strPkgDoc)
        {
            if (pLuaVM == null || pLuaFuncs == null || pLuaPackages == null)
                return;

            LuaPackageDescriptor pPkg = null;

            if (strPackage != null)
            {
                pLuaVM.DoString(strPackage + " = {}");
                pPkg = new LuaPackageDescriptor(strPackage, strPkgDoc);
            }

            Type pTrgType = pTarget.GetType();

            foreach (MethodInfo mInfo in pTrgType.GetMethods())
            {
                foreach (Attribute attr in Attribute.GetCustomAttributes(mInfo))
                {
                    if (attr.GetType() == typeof(AttrLuaFunc))
                    {
                        AttrLuaFunc pAttr = (AttrLuaFunc) attr;
                        ArrayList pParams = new ArrayList();
                        ArrayList pParamDocs = new ArrayList();
                        String strFName = pAttr.getFuncName();
                        String strFDoc = pAttr.getFuncDoc();
                        String[] pPrmDocs = pAttr.getFuncParams();
                        ParameterInfo[] pPrmInfo = mInfo.GetParameters();
                        if (pPrmDocs != null && (pPrmInfo.Length != pPrmDocs.Length))
                        {
                            Console.WriteLine("Function " + mInfo.Name + " (exported as " + strFName + ") argument number mismatch. Declared " + pPrmDocs.Length + " but requires " + pPrmInfo.Length + ".");
                            break;
                        }

                        for (int i = 0; i < pPrmInfo.Length; i++)
                        {
                            pParams.Add(pPrmInfo[i].Name);
                            //pParamDocs.Add(pPrmDocs[i]);
                        }

                        LuaFuncDescriptor pDesc = new LuaFuncDescriptor(strFName, strFDoc, pParams, pParamDocs);
                        if (pPkg != null)
                        {
                            pPkg.AddFunc(pDesc);
                            pLuaVM.RegisterFunction(strPackage + strFName, pTarget, mInfo);
                            pLuaVM.DoString(strPackage + "." + strFName + " = " + strPackage + strFName);
                            pLuaVM.DoString(strPackage + strFName + " = nil");
                        }
                        else
                        {
                            pLuaFuncs.Add(strFName, pDesc);
                            pLuaVM.RegisterFunction(strFName, pTarget, mInfo);
                        }
                    }
                }
            }

            if (pPkg != null)
                pLuaPackages.Add(strPackage, pPkg);
        }
コード例 #3
0
        public void AddFunc(LuaFuncDescriptor pFunc)
        {
            if (PackageFuncs == null)
            {
                PackageFuncs = new Hashtable();
            }

            PackageFuncs.Add(pFunc.getFuncName(), pFunc);
        }
コード例 #4
0
        public void AddFunc(LuaFuncDescriptor pFunc)
        {
            if (PackageFuncs == null)
                PackageFuncs = new Hashtable();

            PackageFuncs.Add(pFunc.getFuncName(), pFunc);
        }
コード例 #5
0
ファイル: lau.cs プロジェクト: g91/BobsPoopTools
        public static void registerLuaFunctions(String strPackage, Object pTarget, String strPkgDoc)
        {
            if (pLuaVM == null || pLuaFuncs == null || pLuaPackages == null)
            {
                return;
            }

            LuaPackageDescriptor pPkg = null;

            if (strPackage != null)
            {
                pLuaVM.DoString(strPackage + " = {}");
                pPkg = new LuaPackageDescriptor(strPackage, strPkgDoc);
            }

            Type pTrgType = pTarget.GetType();

            foreach (MethodInfo mInfo in pTrgType.GetMethods())
            {
                foreach (Attribute attr in Attribute.GetCustomAttributes(mInfo))
                {
                    if (attr.GetType() == typeof(AttrLuaFunc))
                    {
                        AttrLuaFunc     pAttr      = (AttrLuaFunc)attr;
                        ArrayList       pParams    = new ArrayList();
                        ArrayList       pParamDocs = new ArrayList();
                        String          strFName   = pAttr.getFuncName();
                        String          strFDoc    = pAttr.getFuncDoc();
                        String[]        pPrmDocs   = pAttr.getFuncParams();
                        ParameterInfo[] pPrmInfo   = mInfo.GetParameters();
                        if (pPrmDocs != null && (pPrmInfo.Length != pPrmDocs.Length))
                        {
                            Console.WriteLine("Function " + mInfo.Name + " (exported as " + strFName + ") argument number mismatch. Declared " + pPrmDocs.Length + " but requires " + pPrmInfo.Length + ".");
                            break;
                        }

                        for (int i = 0; i < pPrmInfo.Length; i++)
                        {
                            pParams.Add(pPrmInfo[i].Name);
                            //pParamDocs.Add(pPrmDocs[i]);
                        }

                        LuaFuncDescriptor pDesc = new LuaFuncDescriptor(strFName, strFDoc, pParams, pParamDocs);
                        if (pPkg != null)
                        {
                            pPkg.AddFunc(pDesc);
                            pLuaVM.RegisterFunction(strPackage + strFName, pTarget, mInfo);
                            pLuaVM.DoString(strPackage + "." + strFName + " = " + strPackage + strFName);
                            pLuaVM.DoString(strPackage + strFName + " = nil");
                        }
                        else
                        {
                            pLuaFuncs.Add(strFName, pDesc);
                            pLuaVM.RegisterFunction(strFName, pTarget, mInfo);
                        }
                    }
                }
            }

            if (pPkg != null)
            {
                pLuaPackages.Add(strPackage, pPkg);
            }
        }