static private int fillArg(IntPtr ctx, int pos, Type argType, out object arg) { arg = null; DUK_TYPE tsType = (DUK_TYPE)Native.duk_get_type(ctx, pos); if (tsType == DUK_TYPE.NUMBER) { arg = Native.duk_require_int(ctx, pos++); } else if (tsType == DUK_TYPE.STRING) { arg = Native.duk_require_string_s(ctx, pos++); } else if (tsType == DUK_TYPE.OBJECT) { IntPtr ptr = Native.duk_get_heapptr(ctx, pos++); arg = BindObjectsMgr.GetCsObject(ptr); // read object type ARG_TYPE rtType = (ARG_TYPE)Native.duk_require_int(ctx, pos++); if (rtType == ARG_TYPE.OBJECT) { if (arg == null) { throw new Exception("Can not find arg in bindmgr!"); } } else if (rtType == ARG_TYPE.CALLBACK) { int argsCount = Native.duk_require_int(ctx, pos++); Native.duk_push_heapptr(ctx, ptr); int funref = Native.duv_ref(ctx); Context context = Engine.GetContent(ctx); if (context == null) { throw new Exception("Get context failed!"); } TsDelegate td = makeCallBack(context, funref, pos, argsCount); arg = Delegate.CreateDelegate(argType, td, "Deleg", true, true); pos += argsCount; } } return(pos); }
static private TsDelegate makeCallBack(Context context, int funref, int pos, int argsCount) { IntPtr ctx = context.ptr; TsDelegate td = new TsDelegate(context, funref, argsCount); for (int i = 0; i < argsCount; i++) { DUK_TYPE tsType = (DUK_TYPE)Native.duk_get_type(ctx, pos); if (tsType == DUK_TYPE.OBJECT) { Native.duk_dup(ctx, pos); int argref = Native.duv_ref(ctx); pos++; td.AddArgType(i, ARG_TYPE.OBJECT, argref); } else { ARG_TYPE argType = (ARG_TYPE)Native.duk_require_int(ctx, pos++); td.AddArgType(i, argType, 0); } } return(td); }