These are chat archives for ChaiScript/ChaiScript

24th
Aug 2017
Gianluca Aiello
@gianusa_twitter
Aug 24 2017 17:26
I've not found any examples about date/time manipulation using chai script. I've found math functions. Could you give me an example of getting current date and doing some calculations (adding days, hours, etc). Thanks
No0n3Left
@No0n3Left
Aug 24 2017 17:49
@gianusa_twitter For that, you would need to write some functions/classes (or, better yet, use the C++ standard chrono classes) to manage time and wrap over as needed, convert between stuff, etc, and, if you use the chrono one, add it to chaiscript as a user class and add the operators & functions.
Jason Turner
@lefticus
Aug 24 2017 17:58
Correct, there is no date/time stuff exposed to chaiscript by default currently
No0n3Left
@No0n3Left
Aug 24 2017 18:03

How do you add ref-qualified member functions to chaiscript. Whenever I try, I get several errors from chaiscript::fun:

chaiscript/dispatchkit/type_info.hpp:145:15: error: typeid of qualified function type 'int(int&&) const &'
               &typeid(T),
chaiscript/dispatchkit/type_info.hpp:146:15: error: typeid of qualified function type 'chaiscript::detail::Bare_Type<int(int&&) const &>::type {aka int(int&&) const &}'
               &typeid(typename Bare_Type<T>::type));
chaiscript/dispatchkit/proxy_functions.hpp:792:126: error: invalid use of non-static member function of type 'int (std::optional<int>::)(int&&) const &'
           return detail::Handle_Return<typename std::add_lvalue_reference<typename std::add_const<Type>::type>::type>::handle(o->*m_attr);
chaiscript/dispatchkit/proxy_functions.hpp:786:95: error: invalid use of non-static member function of type 'int (std::optional<int>::)(int&&) const &'
           return detail::Handle_Return<typename std::add_lvalue_reference<Type>::type>::handle(o->*m_attr);

This seems to only happen to ref-qualified member functions, here is an example of how I get the error:

template <typename T>
void test()
{
    chaiscript::fun(static_cast<typename T::value_type const& (T::*)() const&>(&T::value);
}
int main()
{
    test<std::optional<int> >();
}
Jason Turner
@lefticus
Aug 24 2017 19:28
Sorry, that's not currently supported (and you're the first user to ask about it). You could get around it with a quick lambda wrapper. chaiscript::fun([](const &T t){ return t.value(); })
No0n3Left
@No0n3Left
Aug 24 2017 19:29
@lefticus Ok, thanks, didnt think of that, but that will work!
Jason Turner
@lefticus
Aug 24 2017 20:33
What compiler are you using?
I'm currently working on some C++17 ports and might end up adding & and && qualified members during that
No0n3Left
@No0n3Left
Aug 24 2017 20:34
@lefticus GCC 7.1.0 with -std=c++17