/* * BuildMethodArgs * * RETURN * null -- fail * not null -- success */ public bool BuildMethodArgs(bool addDefaultValue) { //ArrayList args = new ArrayList(); callParamsLength = 0; for (int i = 0; i < this.arrCSParamsLength; i++) { callParamsLength++; if (i < this.arrJSParamsLength) { JSParam jsParam = arrJSParam[i]; if (jsParam.isWrap) { //args.Add(jsParam.wrappedObj); callParams[i] = jsParam.wrappedObj; } else if (jsParam.isArray) { // todo // Debug.Log("array parameter not supported"); callParams[i] = null; } else if (jsParam.isNull) { //args.Add(null); callParams[i] = null; } else { //args.Add(JSValue_2_CSObject(i)); callParams[i] = JSValue_2_CSObject(i); } } else { if (arrCSParam[i].isOptional) { if (addDefaultValue)//args.Add(arrCSParam[i].defaultValue); { callParams[i] = arrCSParam[i].defaultValue; } else { break; } } else { Debug.LogError("Not enough arguments calling function '" + m_Method.Name + "'"); return(false); } } } //return args.ToArray(); return(true); }
/* * ExtractJSParams * * write into lstJSParam * * RETURN * false -- fail * true -- success * * for primitive, enum, string: not handled */ public bool ExtractJSParams(int start, int count) { arrJSParamsLength = 0; for (int i = 0; i < count; i++) { int index = i + start; bool bUndefined = JSApi.JSh_ArgvIsUndefined(cx, vp, index); if (bUndefined) { return(true); } JSParam jsParam = arrJSParam[arrJSParamsLength++]; //new JSParam(); jsParam.index = index; jsParam.isNull = JSApi.JSh_ArgvIsNull(cx, vp, index); jsParam.isArray = false; jsParam.csObj = null; IntPtr jsObj = JSApi.JSh_ArgvObject(cx, vp, index); if (jsObj == IntPtr.Zero) { jsParam.csObj = null; } // else if (false/*JSApi.JSh_IsArrayObject(cx, jsObj)*/) // { // jsParam.isArray = true; // Debug.LogError("parse js array to cs is not supported"); // } else { object csObj = JSMgr.getCSObj(jsObj); if (csObj == null) { Debug.Log("ExtractJSParams: CSObject is not found"); return(false); } jsParam.csObj = csObj; } //lstJSParam.Add(jsParam); } return(true); }
// index means // lstJSParam[index] // lstCSParam[index] // ps[index] // for calling method public object JSValue_2_CSObject(int index) { JSParam jsParam = arrJSParam[index]; int paramIndex = jsParam.index; CSParam csParam = arrCSParam[index]; //ParameterInfo p = m_ParamInfo[index]; Type t = csParam.type; if (csParam.isRef) { t = t.GetElementType(); } if (jsParam.isNull) { return(null); } else if (jsParam.isWrap) { return(jsParam.wrappedObj); } else if (jsParam.csObj != null) { return(jsParam.csObj); } // if (typeof(UnityEngine.Object).IsAssignableFrom(t)) // { // if (jsParam.isNull) // return null; // // if (jsParam.isWrap) // return jsParam.wrappedObj; // // return jsParam.csObj; // } return(JSValue_2_CSObject(csParam.type, paramIndex)); }
public void Reset(IntPtr cx, IntPtr vp) { if (arrJSParam == null) { arrJSParam = new JSParam[(int)Consts.MaxParams]; arrCSParam = new CSParam[(int)Consts.MaxParams]; for (int i = 0; (int)Consts.MaxParams > i; i++) { arrJSParam[i] = new JSParam(); arrCSParam[i] = new CSParam(); } callParams = new object[(int)Consts.MaxParams]; } arrJSParamsLength = 0; arrCSParamsLength = 0; callParamsLength = 0; m_Method = null; m_ParamInfo = null; this.cx = cx; this.vp = vp; currIndex = 0; }