These are chat archives for ChaiScript/ChaiScript

23rd
Aug 2017
No0n3Left
@No0n3Left
Aug 23 2017 14:55 UTC
I am trying to add some of my own types into ChaiScript, so I can use it for scripting. Im kinda confused on the usage of chaiscript::Boxed_Value. Lets say I want to make module to support std::optional<T>. Which of the following would be more correct:
template<typename T>
chaiscritpt::ModulePtr optional_module<T>(const std::string& typename)
{
    chaiscript::ModulePtr m;
    m->add(chaiscript::user_type<std::optional<T> >("Optional" + typename));
    m->add(chaiscript::fun<T (std::optional<T>::*)(T)>(&std::optional<T>::value_or), "value_or");
    /* ... */
}
chaiscript::ModulePtr optional_module()
{
    chaiscript::ModulePtr m;
    m->add(chaiscript::user_type<std::optional< chaiscript::Boxed_Value> >("Optional"));
    m->add(chaiscript::fun<chaiscript::Boxed_Value (std::optional<chaiscript::Boxed_Value>::*)(chaiscript::Boxed_Value)>(&std::optional<chaiscript::Boxed_Value>::value_or), "value_or");
}
Gianluca Aiello
@gianusa_twitter
Aug 23 2017 16:04 UTC
Which editor could you suggest me with ChaiScript in Windows?
No0n3Left
@No0n3Left
Aug 23 2017 16:06 UTC
@gianusa_twitter I am pretty sure thats just more based on preference. It has a vim highlighting plugin under the main repo contrib/vim. I would just use whatever youre comfortable with, if you want syntax highlighting you may be able to find a plugin for chaiscript in whatever editor you like.
Gianluca Aiello
@gianusa_twitter
Aug 23 2017 16:41 UTC
Thanks @No0n3Left ! Do you know if VIM could be used in Windows?
No0n3Left
@No0n3Left
Aug 23 2017 16:43 UTC
@gianusa_twitter Well, if you are new to vim you have to learn keymappings first, look up vim keymappings (too much to explain here). And you can get vim for windows http://www.vim.org/download.php/#pc
@gianusa_twitter http://openvim.com/ is a good vim tutorial
No0n3Left
@No0n3Left
Aug 23 2017 16:54 UTC
When using chaiscript::utility::add_class(), must i manually add copy and move ctors?
Jason Turner
@lefticus
Aug 23 2017 19:52 UTC
You don't even need to use the contrib/vim, any version of vim or nvim that's been released in the last 5+ years would have chaiscript support
@No0n3Left it depends entirely on what you want to do, do you want an optional Boxed_Value or an optional of a specific type? A Boxed_Value is kind of a catch-all
Vector in chaiscript is a std::vector<Boxed_Value> so that it can hold anything
And yes, you must add your own copy constructor. I strongly suggest you don't add move ctors, the support for that is very poor at the moment
No0n3Left
@No0n3Left
Aug 23 2017 19:55 UTC
@lefticus I have a class that stores settings for the game, and it can return a custom class that is basically an std::variant but it returns optionals rather than throwing if it doesnt hold a type. So, I looked at how the vector was done, and I was basically going to do something like that (where you can specify the exact type with a template and name with a string) for std::optional
Jason Turner
@lefticus
Aug 23 2017 19:56 UTC
I would personally implement it that way, then you could expose the generic Boxed_Value version or whatever.
we should probably implement that support once C++17 support comes around
No0n3Left
@No0n3Left
Aug 23 2017 19:57 UTC
Oh, ok. Do I need to change anything about the contents of the optional (read somewhere that boxed_value requires std::shared_ptr for its type)
Jason Turner
@lefticus
Aug 23 2017 19:58 UTC
Everything that Boxed_Value does with shared_ptr is managed internally to itself
you should not have to worry about that
No0n3Left
@No0n3Left
Aug 23 2017 19:58 UTC
Oh, so I can just have an std::optional<SomeClass> in C++ and send it over to chaiscript and not need to do anything?
Jason Turner
@lefticus
Aug 23 2017 21:44 UTC
You don't have to tell ChaiScript about anything you don't explicitly need. If you did someoptional = somevalue inside of chaiscript then you need that operator= exposed, but nothing else