예제 #1
0
        /*
         * Registers an object's method as a Lua function (global or table field)
         * The method may have any signature
         */
        public LuaFunction RegisterFunction(string path, object target, MethodBase function /*MethodInfo function*/)           //CP: Fix for struct constructor by Alexander Kappner (link: http://luaforge.net/forum/forum.php?thread_id = 2859&forum_id = 145)
        {
            // We leave nothing on the stack when we are done
            int oldTop  = LuaLib.LuaGetTop(luaState);
            var wrapper = new LuaMethodWrapper(translator, target, new ProxyType(function.DeclaringType), function);

            translator.Push(luaState, new LuaNativeFunction(wrapper.invokeFunction));
            this [path] = translator.GetObject(luaState, -1);
            var f = GetFunction(path);

            LuaLib.LuaSetTop(luaState, oldTop);
            return(f);
        }
예제 #2
0
        /*
         * Registers an object's method as a Lua function (global or table field)
         * The method may have any signature
         */
        public LuaFunction RegisterFunction(string path, object target, MethodBase function)
        {
            // We leave nothing on the stack when we are done
            int oldTop  = _luaState.GetTop();
            var wrapper = new LuaMethodWrapper(_translator, target, new ProxyType(function.DeclaringType), function);

            _translator.Push(_luaState, new LuaNativeFunction(wrapper.InvokeFunction));
            this[path] = _translator.GetObject(_luaState, -1);
            var f = GetFunction(path);

            _luaState.SetTop(oldTop);
            return(f);
        }
예제 #3
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);
        }
예제 #4
0
파일: Lua.cs 프로젝트: WolfpawGroup/RTC3
        /*
         * Registers an object's method as a Lua function (global or table field)
         * The method may have any signature
         */
        public LuaFunction RegisterFunction(string path, object target, MethodBase function /*MethodInfo function*/)  //CP: Fix for struct constructor by Alexander Kappner (link: http://luaforge.net/forum/forum.php?thread_id=2859&forum_id=145)
        {
            // We leave nothing on the stack when we are done
            int oldTop = LuaDLL.lua_gettop(luaState);

            LuaMethodWrapper wrapper = new LuaMethodWrapper(translator, target, function.DeclaringType, function);

            translator.push(luaState, new LuaCSFunction(wrapper.call));

            this[path] = translator.getObject(luaState, -1);
            LuaFunction f = GetFunction(path);

            LuaDLL.lua_settop(luaState, oldTop);

            return(f);
        }
예제 #5
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);
        }