return_reference_to.rst.svn-base
来自「本人找过多个在linux下c++的lua5.1封装库,但很少.luabind已经」· SVN-BASE 代码 · 共 80 行
SVN-BASE
80 行
return_reference_to-------------------Motivation~~~~~~~~~~It is very common to return references to arguments or the this-pointer toallow for chaining in C++.:: struct A { float val; A& set(float v) { val = v; return *this; } };When luabind generates code for this, it will create a new object for thereturn-value, pointing to the self-object. This isn't a problem, but could be abit inefficient. When using the return_reference_to-policy we have the abilityto tell luabind that the return-value is already on the lua stack.Defined in~~~~~~~~~~.. parsed-literal:: #include <luabind/return_reference_to_policy.hpp>Synopsis~~~~~~~~.. parsed-literal:: return_reference_to(index)Parameters~~~~~~~~~~========= =============================================================Parameter Purpose========= =============================================================``index`` The argument index to return a reference to, any argument but not ``result``.========= =============================================================Example~~~~~~~.. parsed-literal:: struct A { float val; A& set(float v) { val = v; return \*this; } }; module(L) [ class_<A>("A") .def(constructor<>()) .def("set", &A::set, **return_reference_to(_1)**) ];.. warning:: This policy ignores all type information and should be used only it situations where the parameter type is a perfect match to the return-type (such as in the example).
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?