These are chat archives for ChaiScript/ChaiScript

5th
Jun 2017
Jerry Smith
@dean1012
Jun 05 2017 00:01
I can confirm a class method in the same class that does not utilize boost does work so I think it's an issue with boost
Jerry Smith
@dean1012
Jun 05 2017 00:45
I've rewritten the class to explicitly support the different data types I need and it works fine but if it's possible to get ChaiScript6 (Visual Studio 2017) working with boost 1.64 I'd appreciate any thoughts. The class is a lot cleaner with boost::variant
Jason Turner
@lefticus
Jun 05 2017 02:37
If i understand, what you are wanting is some way for ChaiScript to automatically support conversion from some type (say int) to another type (say boost::variant)
Jerry Smith
@dean1012
Jun 05 2017 02:53
Automatic is always nice, but I don't mind doing a bit of work if you could guide me how to do that conversion either way.
The class as I rewrote it works fine now but it is a lot cleaner (less methods involved) to write it with boost::variant
Jason Turner
@lefticus
Jun 05 2017 03:03
If you wanted to do it manually, you should just need to expose the appropriate constructors: chai.add(chaiscript::constructor<boost::variant (int)>(), "my_variant") then in chaiscript: somethingexpectingvariant(my_variant(5))
Jerry Smith
@dean1012
Jun 05 2017 03:05
My variant is actually defined as boost::variant<bool, std::string, int> so I would need to do chai.add(chaiscript::constructor<boost::variant(bool, std::string, int)>(), "my_variant") then testfunction(my_variant(5)), testfunction(my_variant(true)), testfunction(my_variant("test")) would all work?
Jason Turner
@lefticus
Jun 05 2017 03:07
You would want to add one constructor for each possible input type: chai.add(chaiscript::constructor<boost::variant<bool, std::string, int>(bool)>(), "my_variant"); chai.add(chaiscript::constructor<boost::variant<bool, std::string, int>(std::string)>(), "my_variant"); chai.add(chaiscript::constructor<boost::variant<bool, std::string, int>(int)>(), "my_variant");
Sorry, I left the template parameters out of the first example
Jerry Smith
@dean1012
Jun 05 2017 03:09
Ok that makes sense. Thne I would call in ChaiScript with testfunction(my_variant(<insert whatever type I want>))
Jason Turner
@lefticus
Jun 05 2017 03:11
right
should work with no problem
Jerry Smith
@dean1012
Jun 05 2017 03:11
Thanks
I'll give it a try when I'm done with this other task and let you know how it went
Jerry Smith
@dean1012
Jun 05 2017 04:58
Can I set an explicit type for a variable in ChaiScript?
Your solution worked it seemed on the setters and getters. Problem is, boost::variant determins the type it seems when you actually assign it to a variable. ChaiScript is treating all the values as string.
I can fix that one of two ways. If possible in chaiscript I can do a literal 'bool xyz = ....'
the other is to make ConvertToBool, ConvertToInt, ConvertToString functions.
Jerry Smith
@dean1012
Jun 05 2017 05:04
ahh nevermind. Thanks for your help tonight
Daniel Guzman
@roig
Jun 05 2017 09:03
Hello, how are you maintaining the documentation of the exposed functions using chaiscript in your app? Don't know which is the simple approach to do it...
Jason Turner
@lefticus
Jun 05 2017 12:17
For my stuff in ChaiScript, I write the documentation in doxygen for the chaiscript functions also, and let doxygen generate it
@dean1012 I assume you got it figured out? ChaiScript should never assume a variable is a string, everything is strongly, but automatically, typed
Jerry Smith
@dean1012
Jun 05 2017 22:38
@lefticus Quick question if you don't mind... I have a custom exception defined that I can throw in C++ and catch in Chaiscript but i'm just doing catch(ex) in chaiscript right now.
How can I catch that specific exception?
Jason Turner
@lefticus
Jun 05 2017 22:56
catch (exception_type ex) you just have to expose exception_type to chaiscript if you haven't
it's optionally typed just like function parameters are
Jerry Smith
@dean1012
Jun 05 2017 22:57
what would I use to expose the type? I'm trying to use the add_class utility at the moment and it isn't working well
Nevermind
I think I foudn it
chai.add(chaiscript::user_type<MyClass>(), "MyClass"); (from your cheatsheet)
Jason Turner
@lefticus
Jun 05 2017 23:01
I thought add_class would expose the user_type also, but it's been a long time since I looked at that utility
Jerry Smith
@dean1012
Jun 05 2017 23:02
It might have been, I'm getting the same issue as I did with add_class as when I'm doing user_type manually
Specifically, Visual Studio complains of unhandled exception
Jason Turner
@lefticus
Jun 05 2017 23:03
what is the exception?
The exceptions and their descriptions should be very verbose and give you lots of information about what happened during script execution
no it's my exception that it says isn't handled
Jason Turner
@lefticus
Jun 05 2017 23:04
oooh
Jerry Smith
@dean1012
Jun 05 2017 23:04
but my chai script should be handling it?
this might also be helpful:
The goal is to catch that exception and, if caught, print it out and create a blank gamestate object
Jason Turner
@lefticus
Jun 05 2017 23:07
So you're throwing a typed exception in C++ and trying to catch it in ChaiScript. I might have a bug there
does your exception inherit from std::exception ?
Jerry Smith
@dean1012
Jun 05 2017 23:08
It does (see second pastebin above)
Jason Turner
@lefticus
Jun 05 2017 23:11
ah right
I need to test some things
Jerry Smith
@dean1012
Jun 05 2017 23:11
That's fine. In the meantime, I'll take a step back and see if maybe I'm doing it wrong (from a logic perspective)
In this case I'm using a function called LoadFile(). On the surface, at least two things can go wrong here... Corrupted file, or non existent file. I wanted my chai scripts to be able to detect and differentiate those issues so it can do something like alert the player
I was thinking exceptions would be a neat way to do that but it's possible I may have to make dozens of custom exceptions for that differentiation and something about that seems like I'm doing it wrong.
Jerry Smith
@dean1012
Jun 05 2017 23:16
Do you have a better suggestion by chance?
Jerry Smith
@dean1012
Jun 05 2017 23:23
Also: please see ChaiScript/ChaiScript#351 reported for the potential bug with some source included. If you find it's not a bug, please close
Jerry Smith
@dean1012
Jun 05 2017 23:30
Ok actually I might have found something interesting
In my C++ code, I replaced the throw code with: SaveFileCorruptedException exception; throw exception
I can catch it now if i do catch(ex) { }
However, I still cannot do catch(SaveFileCorruptedException ex)
Jason Turner
@lefticus
Jun 05 2017 23:38
Exceptions or error codes are really the main options, you could also do something like std::expected (probably coming in C++20 or something) where you pass in a different lambda function for each possible error that can occur
Jerry Smith
@dean1012
Jun 05 2017 23:40
I think I'm close to getting this to work. My main problem right now is that I can't get chaiscript to recognize the typed exception
I wonder if I registered it wrong?
catch(ex) works but it works against all exceptions now including my custom exception
catch(CustomException ex) does not throw any errors but also doesn't catch anything
Jason Turner
@lefticus
Jun 05 2017 23:41
No, I see the problem
Jerry Smith
@dean1012
Jun 05 2017 23:42
what's going on?
Jason Turner
@lefticus
Jun 05 2017 23:42
the exact type information for the type of exception it was is lost
I might be able to fix it with std::exception_ptr
Jerry Smith
@dean1012
Jun 05 2017 23:42
so it is a bug in the library?
Jason Turner
@lefticus
Jun 05 2017 23:43
it's more of a limitation of C++ than a bug in ChaiScript
but it might be possible to make it work
Jerry Smith
@dean1012
Jun 05 2017 23:43
I see.
I can avoid the error checking for now just to get work done but eventually I'll have to come up with a different solution if you are unable to resolve it.
I appreciate you looking into it :)
Jason Turner
@lefticus
Jun 05 2017 23:46
it's something I'd like to fix. It's a hole in my "C++ and ChaiScript orthogonality" story. Give me an hour or two, I'll know what's possible
Jerry Smith
@dean1012
Jun 05 2017 23:46
Thanks
Jason Turner
@lefticus
Jun 05 2017 23:53
Btw, if the exception originates inside of ChaiScript, then the type info is fully known, and it works
actually... if you were to throw Boxed_Value(CustomException()); it should work as well
because I can capture the exception type that way