Exemplo n.º 1
0
 public Arg(object arg, ARG_TYPE type, int iref, string typeName)
 {
     this.arg      = arg;
     this.type     = type;
     this.iref     = iref;
     this.typeName = typeName;
 }
Exemplo n.º 2
0
        static private int matchType(IntPtr ctx, int pos, Type type)
        {
            int top = Native.duk_get_top(ctx);

            if (pos >= top)
            {
                return(-1);
            }
            DUK_TYPE tsType = (DUK_TYPE)Native.duk_get_type(ctx, pos++);

            if (tsType == DUK_TYPE.STRING && type.Name == "String")
            {
                return(pos);
            }
            else if (tsType == DUK_TYPE.NUMBER &&
                     (type.Name == "Int16" ||
                      type.Name == "Int32" ||
                      type.Name == "Int64" ||
                      type.Name == "UInt16" ||
                      type.Name == "UInt32" ||
                      type.Name == "UInt64" ||
                      type.Name == "Float" ||
                      type.Name == "Double"))
            {
                return(pos);
            }
            else if (tsType == DUK_TYPE.OBJECT)
            {
                // read object type
                if (pos >= top)
                {
                    return(-1);
                }
                ARG_TYPE rtType = (ARG_TYPE)Native.duk_require_int(ctx, pos++);
                if (rtType == ARG_TYPE.CALLBACK)
                {
                    if (pos >= top)
                    {
                        return(-1);
                    }
                    int argsCount = Native.duk_require_int(ctx, pos++);
                    pos += argsCount;
                    if (pos > top)
                    {
                        return(-1);
                    }
                }
                return(pos);
            }
            return(-1);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 public void AddArgType(int index, ARG_TYPE type, int objRef, string typeName = null)
 {
     _args[index] = new Arg(null, type, objRef, typeName);
 }