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); }
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); } }