예제 #1
0
	LUABIND_API class_info get_class_info(argument const& o)
	{
		lua_State* L = o.interpreter();
	
		o.push(L);
        detail::object_rep* obj = detail::get_instance(L, -1);

        if (!obj)
        {
            class_info result;
            result.name = lua_typename(L, lua_type(L, -1));
            lua_pop(L, 1);
            result.methods = newtable(L);
            result.attributes = newtable(L);
            return result;
        }

        lua_pop(L, 1);

        obj->crep()->get_table(L);
        object table(from_stack(L, -1));
        lua_pop(L, 1);

        class_info result;
        result.name = obj->crep()->name();
        result.methods = newtable(L);
        result.attributes = newtable(L);

        std::size_t index = 1;

        for (iterator i(table), e; i != e; ++i)
        {
            if (type(*i) != LUA_TFUNCTION)
                continue;

            // We have to create a temporary `object` here, otherwise the proxy
            // returned by operator->() will mess up the stack. This is a known
            // problem that probably doesn't show up in real code very often.
            object member(*i);
            member.push(L);
            detail::stack_pop pop(L, 1);

            if (lua_tocfunction(L, -1) == &detail::property_tag)
            {
                result.attributes[index++] = i.key();
            }
            else
            {
                result.methods[i.key()] = *i;
            }
        }

        return result;
	}
예제 #2
0
    void operator()(argument const& self_, BOOST_PP_ENUM_BINARY_PARAMS(N,a,_)) const
    {
        object_rep* self = touserdata<object_rep>(self_);

        std::auto_ptr<T> instance(new T(BOOST_PP_ENUM_PARAMS(N,_)));
        inject_backref(self_.interpreter(), instance.get(), instance.get());

        void* naked_ptr = instance.get();
        Pointer ptr(instance.release());

        void* storage = self->allocate(sizeof(holder_type));

        self->set_instance(new (storage) holder_type(
                               ptr, registered_class<T>::id, naked_ptr));
    }
예제 #3
0
    void operator()(argument const& self_) const
    {
        object_rep* self = touserdata<object_rep>(self_);
        class_rep* cls = self->crep();

        std::auto_ptr<T> instance(new T);
        inject_backref(self_.interpreter(), instance.get(), instance.get());

        void* naked_ptr = instance.get();
        Pointer ptr(instance.release());

        void* storage = self->allocate(sizeof(holder_type));

        self->set_instance(new (storage) holder_type(
            ptr, registered_class<T>::id, naked_ptr, cls));
    }
예제 #4
0
    void operator()(argument const& self_) const
    {
        object_rep* self = touserdata<object_rep>(self_);
#ifdef LUABIND_USE_CXX11
        std::unique_ptr<T> instance(new T);
#else
        std::auto_ptr<T> instance(new T);
#endif
        inject_backref(self_.interpreter(), instance.get(), instance.get());

        void* naked_ptr = instance.get();
        Pointer ptr(instance.release());

        void* storage = self->allocate(sizeof(holder_type));

        self->set_instance(new (storage) holder_type(
#ifdef LUABIND_USE_CXX11
            std::move(ptr), registered_class<T>::id, naked_ptr));
#else
            ptr, registered_class<T>::id, naked_ptr));
#endif
    }