Exemplo n.º 1
0
        static void completeTypeMeta(IntPtr l, LuaCSFunction con, Type self)
        {
            LuaDLL.pua_pushstring(l, ObjectCache.getAQName(self));
            LuaDLL.pua_setfield(l, -3, "__fullname");

            index_func.push(l);
            LuaDLL.pua_setfield(l, -2, "__index");

            newindex_func.push(l);
            LuaDLL.pua_setfield(l, -2, "__newindex");

            if (con == null)
            {
                con = noConstructor;
            }

            pushValue(l, con);
            LuaDLL.pua_setfield(l, -2, "__call");

            LuaDLL.pua_pushcfunction(l, typeToString);
            LuaDLL.pua_setfield(l, -2, "__tostring");

            LuaDLL.pua_pushvalue(l, -1);
            LuaDLL.pua_setmetatable(l, -3);

            LuaDLL.pua_setfield(l, LuaIndexes.LUA_REGISTRYINDEX, self.FullName);
        }
Exemplo n.º 2
0
        public static void createTypeMetatable(IntPtr l, LuaCSFunction con, Type self, Type parent)
        {
            checkMethodValid(con);

            // set parent
            if (parent != null && parent != typeof(object) && parent != typeof(ValueType))
            {
                LuaDLL.pua_pushstring(l, "__parent");
                LuaDLL.puaL_getmetatable(l, ObjectCache.getAQName(parent));
                LuaDLL.pua_rawset(l, -3);

                LuaDLL.pua_pushstring(l, "__parent");
                LuaDLL.puaL_getmetatable(l, parent.FullName);
                LuaDLL.pua_rawset(l, -4);
            }
            else
            {
                LuaDLL.pua_pushstring(l, "__parent");
                LuaDLL.puaL_getmetatable(l, "__luabaseobject");
                LuaDLL.pua_rawset(l, -3);
            }

            completeInstanceMeta(l, self);
            completeTypeMeta(l, con, self);

            LuaDLL.pua_pop(l, 1); // pop type Table
        }
Exemplo n.º 3
0
 public new static void init(IntPtr l)
 {
     LuaDLL.pua_createtable(l, 0, 3);
     LuaObject.pushValue(l, new LuaCSFunction(LuaVarObject.luaIndex));
     LuaDLL.pua_setfield(l, -2, "__index");
     LuaObject.pushValue(l, new LuaCSFunction(LuaVarObject.luaNewIndex));
     LuaDLL.pua_setfield(l, -2, "__newindex");
     LuaDLL.pua_pushcfunction(l, LuaObject.lua_gc);
     LuaDLL.pua_setfield(l, -2, "__gc");
     LuaDLL.pua_setfield(l, LuaIndexes.LUA_REGISTRYINDEX, "LuaVarObject");
     LuaDLL.pua_createtable(l, 0, 1);
     LuaObject.pushValue(l, new LuaCSFunction(LuaVarObject.methodWrapper));
     LuaDLL.pua_setfield(l, -2, "__call");
     LuaDLL.pua_setfield(l, LuaIndexes.LUA_REGISTRYINDEX, ObjectCache.getAQName(typeof(LuaCSFunction)));
 }
Exemplo n.º 4
0
        internal void push(IntPtr l, object o, bool checkReflect, bool isArray = false)
        {
            if (o == null)
            {
                LuaDLL.pua_pushnil(l);
                return;
            }
            int  index = -1;
            bool flag  = this.isGcObject(o);
            bool flag2 = flag && this.objMap.TryGetValue(o, out index);

            if (flag2 && LuaDLL.luaS_getcacheud(l, index, this.udCacheRef) == 1)
            {
                return;
            }
            index = this.add(o);
            LuaDLL.luaS_pushobject(l, index, (!isArray) ? ObjectCache.getAQName(o) : "LuaArray", flag, this.udCacheRef);
        }
Exemplo n.º 5
0
        private static void completeInstanceMeta(IntPtr l, Type self)
        {
            LuaDLL.pua_pushstring(l, "__typename");
            LuaDLL.pua_pushstring(l, self.Name);
            LuaDLL.pua_rawset(l, -3);

            // for instance
            index_func.push(l);
            LuaDLL.pua_setfield(l, -2, "__index");

            newindex_func.push(l);
            LuaDLL.pua_setfield(l, -2, "__newindex");

            pushValue(l, lua_add);
            LuaDLL.pua_setfield(l, -2, "__add");
            pushValue(l, lua_sub);
            LuaDLL.pua_setfield(l, -2, "__sub");
            pushValue(l, lua_mul);
            LuaDLL.pua_setfield(l, -2, "__mul");
            pushValue(l, lua_div);
            LuaDLL.pua_setfield(l, -2, "__div");
            pushValue(l, lua_unm);
            LuaDLL.pua_setfield(l, -2, "__unm");
            pushValue(l, lua_eq);
            LuaDLL.pua_setfield(l, -2, "__eq");
            pushValue(l, lua_le);
            LuaDLL.pua_setfield(l, -2, "__le");
            pushValue(l, lua_lt);
            LuaDLL.pua_setfield(l, -2, "__lt");
            pushValue(l, lua_tostring);
            LuaDLL.pua_setfield(l, -2, "__tostring");

            LuaDLL.pua_pushcfunction(l, lua_gc);
            LuaDLL.pua_setfield(l, -2, "__gc");

            if (self.IsValueType && isImplByLua(self))
            {
                LuaDLL.pua_pushvalue(l, -1);
                LuaDLL.pua_setglobal(l, self.FullName + ".Instance");
            }
            LuaDLL.pua_setfield(l, LuaIndexes.LUA_REGISTRYINDEX, ObjectCache.getAQName(self));
        }
Exemplo n.º 6
0
        private static string getAQName(object o)
        {
            Type type = o.GetType();

            return(ObjectCache.getAQName(type));
        }