Exemplo n.º 1
0
        public ObjectTranslator(LuaEnv luaenv, RealStatePtr L)
        {
            assemblies = new List <Assembly>();

            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                assemblies.Add(assembly);
            }

            this.luaEnv      = luaenv;
            objectCasters    = new ObjectCasters(this);
            objectCheckers   = new ObjectCheckers(this);
            methodWrapsCache = new MethodWrapsCache(this, objectCheckers, objectCasters);
            metaFunctions    = new StaticLuaCallbacks();

            importTypeFunction   = new LuaCSFunction(StaticLuaCallbacks.ImportType);
            loadAssemblyFunction = new LuaCSFunction(StaticLuaCallbacks.LoadAssembly);
            castFunction         = new LuaCSFunction(StaticLuaCallbacks.Cast);

            LuaAPI.lua_newtable(L);
            LuaAPI.lua_newtable(L);
            LuaAPI.xlua_pushasciistring(L, "__mode");
            LuaAPI.xlua_pushasciistring(L, "v");
            LuaAPI.lua_rawset(L, -3);
            LuaAPI.lua_setmetatable(L, -2);
            cacheRef = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);

            initCSharpCallLua();
        }
Exemplo n.º 2
0
        static int _m_GetMethodWrap(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                XLua.MethodWrapsCache gen_to_be_invoked = (XLua.MethodWrapsCache)translator.FastGetCSObj(L, 1);



                {
                    System.Type _type       = (System.Type)translator.GetObject(L, 2, typeof(System.Type));
                    string      _methodName = LuaAPI.lua_tostring(L, 3);

                    XLua.LuaDLL.lua_CSFunction gen_ret = gen_to_be_invoked.GetMethodWrap(_type, _methodName);
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Exemplo n.º 3
0
        static int _m__GenMethodWrap(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                XLua.MethodWrapsCache gen_to_be_invoked = (XLua.MethodWrapsCache)translator.FastGetCSObj(L, 1);


                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 5 && translator.Assignable <System.Type>(L, 2) && (LuaAPI.lua_isnil(L, 3) || LuaAPI.lua_type(L, 3) == LuaTypes.LUA_TSTRING) && translator.Assignable <System.Collections.Generic.IEnumerable <System.Reflection.MemberInfo> >(L, 4) && LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type(L, 5))
                {
                    System.Type _type       = (System.Type)translator.GetObject(L, 2, typeof(System.Type));
                    string      _methodName = LuaAPI.lua_tostring(L, 3);
                    System.Collections.Generic.IEnumerable <System.Reflection.MemberInfo> _methodBases = (System.Collections.Generic.IEnumerable <System.Reflection.MemberInfo>)translator.GetObject(L, 4, typeof(System.Collections.Generic.IEnumerable <System.Reflection.MemberInfo>));
                    bool _forceCheck = LuaAPI.lua_toboolean(L, 5);

                    XLua.MethodWrap gen_ret = gen_to_be_invoked._GenMethodWrap(_type, _methodName, _methodBases, _forceCheck);
                    translator.Push(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 4 && translator.Assignable <System.Type>(L, 2) && (LuaAPI.lua_isnil(L, 3) || LuaAPI.lua_type(L, 3) == LuaTypes.LUA_TSTRING) && translator.Assignable <System.Collections.Generic.IEnumerable <System.Reflection.MemberInfo> >(L, 4))
                {
                    System.Type _type       = (System.Type)translator.GetObject(L, 2, typeof(System.Type));
                    string      _methodName = LuaAPI.lua_tostring(L, 3);
                    System.Collections.Generic.IEnumerable <System.Reflection.MemberInfo> _methodBases = (System.Collections.Generic.IEnumerable <System.Reflection.MemberInfo>)translator.GetObject(L, 4, typeof(System.Collections.Generic.IEnumerable <System.Reflection.MemberInfo>));

                    XLua.MethodWrap gen_ret = gen_to_be_invoked._GenMethodWrap(_type, _methodName, _methodBases);
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to XLua.MethodWrapsCache._GenMethodWrap!"));
        }
Exemplo n.º 4
0
        static int __CreateInstance(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                if (LuaAPI.lua_gettop(L) == 4 && translator.Assignable <XLua.ObjectTranslator>(L, 2) && translator.Assignable <XLua.ObjectCheckers>(L, 3) && translator.Assignable <XLua.ObjectCasters>(L, 4))
                {
                    XLua.ObjectTranslator _translator  = (XLua.ObjectTranslator)translator.GetObject(L, 2, typeof(XLua.ObjectTranslator));
                    XLua.ObjectCheckers   _objCheckers = (XLua.ObjectCheckers)translator.GetObject(L, 3, typeof(XLua.ObjectCheckers));
                    XLua.ObjectCasters    _objCasters  = (XLua.ObjectCasters)translator.GetObject(L, 4, typeof(XLua.ObjectCasters));

                    XLua.MethodWrapsCache gen_ret = new XLua.MethodWrapsCache(_translator, _objCheckers, _objCasters);
                    translator.Push(L, gen_ret);

                    return(1);
                }
            }
            catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(LuaAPI.luaL_error(L, "invalid arguments to XLua.MethodWrapsCache constructor!"));
        }
Exemplo n.º 5
0
        public ObjectTranslator(LuaEnv luaenv, RealStatePtr L)
        {
#if XLUA_GENERAL
            var dumb_field = typeof(ObjectTranslator).GetField("s_gen_reg_dumb_obj", BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.NonPublic);
            if (dumb_field != null)
            {
                dumb_field.GetValue(null);
            }
#endif
            assemblies = new List <Assembly>();

            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                assemblies.Add(assembly);
            }

            this.luaEnv      = luaenv;
            objectCasters    = new ObjectCasters(this);
            objectCheckers   = new ObjectCheckers(this);
            methodWrapsCache = new MethodWrapsCache(this, objectCheckers, objectCasters);
            metaFunctions    = new StaticLuaCallbacks();

            importTypeFunction   = new LuaCSFunction(StaticLuaCallbacks.ImportType);
            loadAssemblyFunction = new LuaCSFunction(StaticLuaCallbacks.LoadAssembly);
            castFunction         = new LuaCSFunction(StaticLuaCallbacks.Cast);
            cTypeFunction        = new LuaCSFunction(StaticLuaCallbacks.Ctype);

            LuaAPI.lua_newtable(L);
            LuaAPI.lua_newtable(L);
            LuaAPI.xlua_pushasciistring(L, "__mode");
            LuaAPI.xlua_pushasciistring(L, "v");
            LuaAPI.lua_rawset(L, -3);
            LuaAPI.lua_setmetatable(L, -2);
            cacheRef = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);

            initCSharpCallLua();
        }