コード例 #1
0
        private Type TypeOf(LuaState luaState, int idx)
        {
            int udata = luaState.CheckUObject(idx, "luaNet_class");

            if (udata == -1)
            {
                return(null);
            }

            var pt = (ProxyType)_objects[udata];

            return(pt.UnderlyingSystemType);
        }
コード例 #2
0
        private int GetMethodSignatureInternal(LuaState luaState)
        {
            ProxyType klass;
            object    target;
            int       udata = luaState.CheckUObject(1, "luaNet_class");

            if (udata != -1)
            {
                klass  = (ProxyType)_objects[udata];
                target = null;
            }
            else
            {
                target = GetRawNetObject(luaState, 1);

                if (target == null)
                {
                    ThrowError(luaState, "get_method_bysig: first arg is not type or object reference");
                    luaState.PushNil();
                    return(1);
                }

                klass = new ProxyType(target.GetType());
            }

            string methodName = luaState.ToString(2, false);
            var    signature  = new Type[luaState.GetTop() - 2];

            for (int i = 0; i < signature.Length; i++)
            {
                signature[i] = FindType(luaState.ToString(i + 3, false));
            }

            try
            {
                var method = klass.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static |
                                             BindingFlags.Instance, signature);
                var wrapper = new LuaMethodWrapper(this, target, klass, method);
                LuaNativeFunction invokeDelegate = wrapper.InvokeFunction;
                PushFunction(luaState, invokeDelegate);
            }
            catch (Exception e)
            {
                ThrowError(luaState, e);
                luaState.PushNil();
            }

            return(1);
        }
コード例 #3
0
        private int GetConstructorSignatureInternal(LuaState luaState)
        {
            ProxyType klass = null;
            int       udata = luaState.CheckUObject(1, "luaNet_class");

            if (udata != -1)
            {
                klass = (ProxyType)_objects[udata];
            }

            if (klass == null)
            {
                ThrowError(luaState, "get_constructor_bysig: first arg is invalid type reference");
            }

            var signature = new Type[luaState.GetTop() - 1];

            for (int i = 0; i < signature.Length; i++)
            {
                signature[i] = FindType(luaState.ToString(i + 2, false));
            }

            try
            {
                ConstructorInfo constructor    = klass.UnderlyingSystemType.GetConstructor(signature);
                var             wrapper        = new LuaMethodWrapper(this, null, klass, constructor);
                var             invokeDelegate = wrapper.InvokeFunction;
                PushFunction(luaState, invokeDelegate);
            }
            catch (Exception e)
            {
                ThrowError(luaState, e);
                luaState.PushNil();
            }
            return(1);
        }