These are chat archives for ChaiScript/ChaiScript

Mar 2018
Jason Turner
Mar 06 2018 00:06
Technically no type name is ever needed to be provided to chaiscript, but it can help with error messages, can let you make typed functions and in the case of the example from @mackiem gives you the ability to construct an object of the type
Tharindu Mathew
Mar 06 2018 02:31
Thanks, I got my use case working. @lefticus as you can see, some people do refer your docs a lot :).. it's just that some subtle points create doubts... Anyway I'm hoping to make some time to contribute. Really want to learn about parsing, and creating a language through chaiscript
Tyler Lewis
Mar 06 2018 19:54

enum SomeEnum : int { ItemOne = 0, ItemTwo = 1 };
void useEnum(SomeEnum someEnum) {...};
chaiEngine.add(fun(useEnum), "useEnum");
chaiEngine.add(user_type<SomeEnum>(), "SomeEnum");
chaiEngine.add(type_conversion<SomeEnum, int>());
chaiEngine.add(type_conversion<int, SomeEnum>()); //Hard compile error (std::is_convertible fails)
chaiEngine.add_global_const(const_var(SomeEnum::ItemOne), "SE_ItemOne");
chaiEngine.add_global_const(const_var(SomeEnum::ItemTwo), "SE_ItemTwo");
var myEnum = SE_ItemOne;

Two questions here:
1.) Is there any way to have chaiscript automatically convert the parmeter SomeEnum to int for the function call? One solution would be adding a lambda with a static_cast to the engine, but I was hoping to be able to automatically do it
2.) Why does the to, from type conversion fail for int -> SomeEnum? I would have thought (since it is a plain enum) that both ways would work. This may be more of a C++ question, though

maybe relevant
Tharindu Mathew
Mar 06 2018 22:19
i think it's enforced to ensure type correctness. So, you are explicitly casting and making sure of it.
Tyler Lewis
Mar 06 2018 22:20
Oh yeah, that makes sense