예제 #1
0
 private void FillCallArgs(IntPtr ctx)
 {
     foreach (Arg a in _args)
     {
         Type t = a.arg.GetType();
         if (a.type == ARG_TYPE.OBJECT)
         {
             Native.duv_push_ref(ctx, a.iref);
             Bind.PushDynCsObject(ctx, a.arg, -1);
             Native.duk_remove(ctx, -2);
         }
         else if (a.type == ARG_TYPE.CSOBJECT)
         {
             Bind.PushCsObject(ctx, a.arg, a.typeName);
         }
         else if (t.IsEnum || t.Name == "Int32")
         {
             Uts.Native.duk_push_int(ctx, Convert.ToInt32(a.arg));
         }
         else if (t.Name == "UInt32")
         {
             Uts.Native.duk_push_uint(ctx, Convert.ToUInt32(a.arg));
         }
         else if (t.Name == "Float" || t.Name == "Double")
         {
             Uts.Native.duk_push_number(ctx, Convert.ToDouble(a.arg));
         }
         else if (t.Name == "Boolean")
         {
             Uts.Native.duk_push_boolean(ctx, Convert.ToBoolean(a.arg) ? 1 : 0);
         }
         else if (t.Name == "String")
         {
             Uts.Native.duk_push_string(ctx, Convert.ToString(a.arg));
         }
         else
         {
             Uts.Native.duk_push_undefined(ctx);
         }
     }
 }
예제 #2
0
 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)));
     }
 }
예제 #3
0
        static private int pushRetVal(IntPtr ctx, object ret, RET_TYPE retType, string member, Type type, int tsTypePos)
        {
            Type t = ret.GetType();

            if (retType == RET_TYPE.CLASSOBJECT)
            {
                Bind.PushDynCsObject(ctx, ret, tsTypePos);
            }
            else if (t.IsEnum || t.Name == "Int32")
            {
                Native.duk_push_int(ctx, Convert.ToInt32(ret));
            }
            else if (t.Name == "String")
            {
                Native.duk_push_string(ctx, Convert.ToString(ret));
            }
            else
            {
                throw new Exception(string.Format("Return value is invalid! attr<{0}> in {1} return type is {2}.", member, type.Name, t.Name));
            }
            return(1);
        }