public static Object RequireThis(IntPtr ctx) { Native.duk_push_this(ctx); IntPtr ptr = Native.duk_get_heapptr(ctx, -1); Native.duk_pop(ctx); return(BindObjectsMgr.GetCsObject(ptr)); }
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 public int __as(IntPtr ctx) { try { // read params IntPtr optr = Native.duk_get_heapptr(ctx, 0); object o = BindObjectsMgr.GetCsObject(optr); string sretType = Native.duk_require_string_s(ctx, 1); // stack.pos2 is tsToTypeClass Type retType = Type.GetType(sretType); if (retType == null) { throw new Exception(string.Format("Not find class {0} type when as op.", sretType)); } BindObjectsMgr.RemoveByCsObject(o); Bind.PushDynCsObject(ctx, Convert.ChangeType(o, retType), 2); return(1); } catch (Exception e) { return(Native.duk_throw_error(ctx, Convert.ToString(e))); } }