Ejemplo n.º 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;
	}
Ejemplo n.º 2
0
 utree eval(scope const& env) const
 {
     scope const* eptr = &env;
     utree result;
     for (std::size_t i = n; i < eptr->size(); ++i)
     {
         utree const& arg = (*eptr)[i];
         if (arg.which() != utree_type::function_type)
             result.push_back(utree(boost::ref(arg)));
         else
             result.push_back(arg.eval(*eptr));
     }
     return result;
 }
Ejemplo n.º 3
0
void execute_clamp(opcode_t opcode, const argument& a,
                                    const argument& b)
{
	const clamp_args_t* args = b.get<const clamp_args_t*>();
	usize_t size = a.size();
	launchcfg cfg = make_elemwise_launchcfg(size);
	launch_clamp(cfg.gdim,cfg.bdim,cfg.smem,cfg.stream,
	             size,a.dtype,
	             a.get<void*>(),
	             args->lo,args->hi);
}
Ejemplo n.º 4
0
// execution function:
//    Called when the virtual machine gets around to executing 
//    the lerp instruction, long after it was validated and inserted
//    into the execution stream. 
//    A CUDA execution function configures and calls a CUDA kernel.
//
void execute_lerp(opcode_t opcode, const argument& a,
                                   const argument& b,
                                   const argument& c,
                                   const argument& alpha)
{
	usize_t size = a.size();
	launchcfg cfg = make_elemwise_launchcfg(size);
	launch_lerp(cfg.gdim,cfg.bdim,cfg.smem,cfg.stream,
	                size,a.dtype,
	                a.get<const void*>(),
	                b.get<const void*>(),
	                c.get<      void*>(),
	                alpha.get<double>());

}
Ejemplo n.º 5
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));
    }
Ejemplo n.º 6
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));
    }
Ejemplo n.º 7
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
    }
Ejemplo n.º 8
0
string_view get_enumeration_name(const argument& arg)
{
    return arg.get_type().get_enumeration().value_to_name(arg);
}