Merge branch 'return_value_handling' into develop
This commit is contained in:
commit
a3f88b43ce
@ -38,9 +38,10 @@ namespace chaiscript
|
|||||||
Data(const Type_Info &ti,
|
Data(const Type_Info &ti,
|
||||||
chaiscript::detail::Any to,
|
chaiscript::detail::Any to,
|
||||||
bool tr,
|
bool tr,
|
||||||
const void *t_void_ptr)
|
const void *t_void_ptr,
|
||||||
|
bool t_return_value)
|
||||||
: m_type_info(ti), m_obj(std::move(to)), m_data_ptr(ti.is_const()?nullptr:const_cast<void *>(t_void_ptr)), m_const_data_ptr(t_void_ptr),
|
: m_type_info(ti), m_obj(std::move(to)), m_data_ptr(ti.is_const()?nullptr:const_cast<void *>(t_void_ptr)), m_const_data_ptr(t_void_ptr),
|
||||||
m_is_ref(tr)
|
m_is_ref(tr), m_return_value(t_return_value)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ namespace chaiscript
|
|||||||
m_is_ref = rhs.m_is_ref;
|
m_is_ref = rhs.m_is_ref;
|
||||||
m_data_ptr = rhs.m_data_ptr;
|
m_data_ptr = rhs.m_data_ptr;
|
||||||
m_const_data_ptr = rhs.m_const_data_ptr;
|
m_const_data_ptr = rhs.m_const_data_ptr;
|
||||||
|
m_return_value = rhs.m_return_value;
|
||||||
|
|
||||||
if (rhs.m_attrs)
|
if (rhs.m_attrs)
|
||||||
{
|
{
|
||||||
@ -74,76 +76,81 @@ namespace chaiscript
|
|||||||
const void *m_const_data_ptr;
|
const void *m_const_data_ptr;
|
||||||
std::unique_ptr<std::map<std::string, Boxed_Value>> m_attrs;
|
std::unique_ptr<std::map<std::string, Boxed_Value>> m_attrs;
|
||||||
bool m_is_ref;
|
bool m_is_ref;
|
||||||
|
bool m_return_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Object_Data
|
struct Object_Data
|
||||||
{
|
{
|
||||||
static std::shared_ptr<Data> get(Boxed_Value::Void_Type)
|
static std::shared_ptr<Data> get(Boxed_Value::Void_Type, bool t_return_value)
|
||||||
{
|
{
|
||||||
return std::make_shared<Data>(
|
return std::make_shared<Data>(
|
||||||
detail::Get_Type_Info<void>::get(),
|
detail::Get_Type_Info<void>::get(),
|
||||||
chaiscript::detail::Any(),
|
chaiscript::detail::Any(),
|
||||||
false,
|
false,
|
||||||
nullptr)
|
nullptr,
|
||||||
|
t_return_value)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static std::shared_ptr<Data> get(const std::shared_ptr<T> *obj)
|
static std::shared_ptr<Data> get(const std::shared_ptr<T> *obj, bool t_return_value)
|
||||||
{
|
{
|
||||||
return get(*obj);
|
return get(*obj, t_return_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static std::shared_ptr<Data> get(const std::shared_ptr<T> &obj)
|
static std::shared_ptr<Data> get(const std::shared_ptr<T> &obj, bool t_return_value)
|
||||||
{
|
{
|
||||||
return std::make_shared<Data>(
|
return std::make_shared<Data>(
|
||||||
detail::Get_Type_Info<T>::get(),
|
detail::Get_Type_Info<T>::get(),
|
||||||
chaiscript::detail::Any(obj),
|
chaiscript::detail::Any(obj),
|
||||||
false,
|
false,
|
||||||
obj.get()
|
obj.get(),
|
||||||
|
t_return_value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static std::shared_ptr<Data> get(std::shared_ptr<T> &&obj)
|
static std::shared_ptr<Data> get(std::shared_ptr<T> &&obj, bool t_return_value)
|
||||||
{
|
{
|
||||||
auto ptr = obj.get();
|
auto ptr = obj.get();
|
||||||
return std::make_shared<Data>(
|
return std::make_shared<Data>(
|
||||||
detail::Get_Type_Info<T>::get(),
|
detail::Get_Type_Info<T>::get(),
|
||||||
chaiscript::detail::Any(std::move(obj)),
|
chaiscript::detail::Any(std::move(obj)),
|
||||||
false,
|
false,
|
||||||
ptr
|
ptr,
|
||||||
|
t_return_value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static std::shared_ptr<Data> get(T *t)
|
static std::shared_ptr<Data> get(T *t, bool t_return_value)
|
||||||
{
|
{
|
||||||
return get(std::ref(*t));
|
return get(std::ref(*t), t_return_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static std::shared_ptr<Data> get(const T *t)
|
static std::shared_ptr<Data> get(const T *t, bool t_return_value)
|
||||||
{
|
{
|
||||||
return get(std::cref(*t));
|
return get(std::cref(*t), t_return_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static std::shared_ptr<Data> get(std::reference_wrapper<T> obj)
|
static std::shared_ptr<Data> get(std::reference_wrapper<T> obj, bool t_return_value)
|
||||||
{
|
{
|
||||||
auto p = &obj.get();
|
auto p = &obj.get();
|
||||||
return std::make_shared<Data>(
|
return std::make_shared<Data>(
|
||||||
detail::Get_Type_Info<T>::get(),
|
detail::Get_Type_Info<T>::get(),
|
||||||
chaiscript::detail::Any(std::move(obj)),
|
chaiscript::detail::Any(std::move(obj)),
|
||||||
true,
|
true,
|
||||||
p
|
p,
|
||||||
|
t_return_value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static std::shared_ptr<Data> get(T t)
|
static std::shared_ptr<Data> get(T t, bool t_return_value)
|
||||||
{
|
{
|
||||||
auto p = std::make_shared<T>(std::move(t));
|
auto p = std::make_shared<T>(std::move(t));
|
||||||
auto ptr = p.get();
|
auto ptr = p.get();
|
||||||
@ -151,7 +158,8 @@ namespace chaiscript
|
|||||||
detail::Get_Type_Info<T>::get(),
|
detail::Get_Type_Info<T>::get(),
|
||||||
chaiscript::detail::Any(std::move(p)),
|
chaiscript::detail::Any(std::move(p)),
|
||||||
false,
|
false,
|
||||||
ptr
|
ptr,
|
||||||
|
t_return_value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +169,8 @@ namespace chaiscript
|
|||||||
Type_Info(),
|
Type_Info(),
|
||||||
chaiscript::detail::Any(),
|
chaiscript::detail::Any(),
|
||||||
false,
|
false,
|
||||||
nullptr
|
nullptr,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,8 +180,8 @@ namespace chaiscript
|
|||||||
/// Basic Boxed_Value constructor
|
/// Basic Boxed_Value constructor
|
||||||
template<typename T,
|
template<typename T,
|
||||||
typename = typename std::enable_if<!std::is_same<Boxed_Value, typename std::decay<T>::type>::value>::type>
|
typename = typename std::enable_if<!std::is_same<Boxed_Value, typename std::decay<T>::type>::value>::type>
|
||||||
explicit Boxed_Value(T &&t)
|
explicit Boxed_Value(T &&t, bool t_return_value = false)
|
||||||
: m_data(Object_Data::get(std::forward<T>(t)))
|
: m_data(Object_Data::get(std::forward<T>(t), t_return_value))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,6 +248,16 @@ namespace chaiscript
|
|||||||
return m_data->m_is_ref;
|
return m_data->m_is_ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_return_value() const CHAISCRIPT_NOEXCEPT
|
||||||
|
{
|
||||||
|
return m_data->m_return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset_return_value() const CHAISCRIPT_NOEXCEPT
|
||||||
|
{
|
||||||
|
m_data->m_return_value = false;
|
||||||
|
}
|
||||||
|
|
||||||
bool is_pointer() const CHAISCRIPT_NOEXCEPT
|
bool is_pointer() const CHAISCRIPT_NOEXCEPT
|
||||||
{
|
{
|
||||||
return !is_ref();
|
return !is_ref();
|
||||||
|
@ -38,14 +38,14 @@ namespace chaiscript
|
|||||||
typename = typename std::enable_if<std::is_pod<typename std::decay<T>::type>::value>::type>
|
typename = typename std::enable_if<std::is_pod<typename std::decay<T>::type>::value>::type>
|
||||||
static Boxed_Value handle(T r)
|
static Boxed_Value handle(T r)
|
||||||
{
|
{
|
||||||
return Boxed_Value(std::move(r));
|
return Boxed_Value(std::move(r), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T,
|
template<typename T,
|
||||||
typename = typename std::enable_if<!std::is_pod<typename std::decay<T>::type>::value>::type>
|
typename = typename std::enable_if<!std::is_pod<typename std::decay<T>::type>::value>::type>
|
||||||
static Boxed_Value handle(T &&r)
|
static Boxed_Value handle(T &&r)
|
||||||
{
|
{
|
||||||
return Boxed_Value(std::make_shared<T>(std::forward<T>(r)));
|
return Boxed_Value(std::make_shared<T>(std::forward<T>(r)), true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
static Boxed_Value handle(Ret *p)
|
static Boxed_Value handle(Ret *p)
|
||||||
{
|
{
|
||||||
return Boxed_Value(p);
|
return Boxed_Value(p, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
static Boxed_Value handle(const Ret *p)
|
static Boxed_Value handle(const Ret *p)
|
||||||
{
|
{
|
||||||
return Boxed_Value(p);
|
return Boxed_Value(p, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
static Boxed_Value handle(const std::shared_ptr<Ret> &r)
|
static Boxed_Value handle(const std::shared_ptr<Ret> &r)
|
||||||
{
|
{
|
||||||
return Boxed_Value(r);
|
return Boxed_Value(r, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
static Boxed_Value handle(const std::shared_ptr<Ret> &r)
|
static Boxed_Value handle(const std::shared_ptr<Ret> &r)
|
||||||
{
|
{
|
||||||
return Boxed_Value(r);
|
return Boxed_Value(r, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
static Boxed_Value handle(const std::shared_ptr<Ret> &r)
|
static Boxed_Value handle(const std::shared_ptr<Ret> &r)
|
||||||
{
|
{
|
||||||
return Boxed_Value(r);
|
return Boxed_Value(r, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
static Boxed_Value handle(const Ret &r)
|
static Boxed_Value handle(const Ret &r)
|
||||||
{
|
{
|
||||||
return Boxed_Value(std::cref(r));
|
return Boxed_Value(std::cref(r), true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -569,7 +569,12 @@ namespace chaiscript
|
|||||||
lhs.assign(rhs);
|
lhs.assign(rhs);
|
||||||
return rhs;
|
return rhs;
|
||||||
} else {
|
} else {
|
||||||
rhs = t_ss.call_function("clone", rhs);
|
if (!rhs.is_return_value())
|
||||||
|
{
|
||||||
|
rhs = t_ss.call_function("clone", rhs);
|
||||||
|
} else {
|
||||||
|
rhs.reset_return_value();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,8 @@ void take_shared_ptr(const std::shared_ptr<const std::string> &p)
|
|||||||
int main(int /*argc*/, char * /*argv*/[]) {
|
int main(int /*argc*/, char * /*argv*/[]) {
|
||||||
using namespace chaiscript;
|
using namespace chaiscript;
|
||||||
|
|
||||||
ChaiScript chai;
|
ChaiScript chai(chaiscript::Std_Lib::library());
|
||||||
|
|
||||||
|
|
||||||
//Create a new system object and share it with the chaiscript engine
|
//Create a new system object and share it with the chaiscript engine
|
||||||
System system;
|
System system;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user