Ejemplo n.º 1
0
        static int _Call(lua_State L)
        {
            try
            {
                int              n             = lua_gettop(L);
                MethodBase       methodInfo    = null;
                ParameterInfo[]  parameterInfo = null;
                object[]         args          = null;
                MethodReflection method        = ToLightObject <MethodReflection>(L, lua_upvalueindex(1), false);
                CallDel          callDel       = null;
                Delegate         del           = null;
                for (int i = 0; i < method.methodInfo.Length; i++)
                {
                    var m          = method.methodInfo[i];
                    var paramInfo  = method.parameters[i];
                    int paramCount = n - 1;
#if !LUNA_SCRIPT
                    if (m.IsStatic)
                    {
                        paramCount = n;
                    }
#endif
                    if (paramInfo.Length == paramCount && CheckParameterType(L, n - paramCount + 1, paramInfo))
                    {
                        //todo:CheckType
                        methodInfo    = m;
                        parameterInfo = paramInfo;
                        args          = method.args[i];
                        callDel       = method.luaFunc[i];
                        del           = method.del[i];
                        break;
                    }
                }

                if (callDel != null)
                {
                    return(callDel(L, methodInfo.IsStatic ? 2 : 1, del));
                }

#if LUNA_SCRIPT
                int StackStart = 2;
#else
                int StackStart = methodInfo.IsStatic ? 1 : 2;
#endif

                for (int i = 0; i < args.Length; i++)
                {
                    args[i] = GetObject(L, i + StackStart, parameterInfo[i].ParameterType);
                }

                if (methodInfo.IsConstructor)
                {
                    object ret = ((ConstructorInfo)methodInfo).Invoke(args);
                    Array.Clear(args, 0, args.Length);
                    Push(L, ret);
                    return(1);
                }
                else
                {
                    object     obj = methodInfo.IsStatic ? null : GetObject(L, 1, methodInfo.ReflectedType);
                    MethodInfo mi  = methodInfo as MethodInfo;
                    object     ret = methodInfo.Invoke(obj, args);
                    Array.Clear(args, 0, args.Length);

                    if (mi.ReturnType != typeof(void))
                    {
                        Push(L, ret);
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
            catch (Exception e)
            {
                return(luaL_error(L, e.Message));
            }
        }
Ejemplo n.º 2
0
 public void Running(CallDel d)
 {
     Console.WriteLine("Program Running.....");
     d();
 }