These are chat archives for ChaiScript/ChaiScript

6th
Jun 2017
Jerry Smith
@dean1012
Jun 06 2017 00:59
Let me try that
that seems to have solved the typing issue! But now it gives me a problem trying to do ex.what()
it says: expected const exception
i think i can resolve this. let me try something
Jerry Smith
@dean1012
Jun 06 2017 01:07
ok so this is interesting and fun. I finally have it working! but I may have come across a different issue that is either a bug or I'm doing something wrong again
first, I had to stop using user_type and go back to using add_class which makes the what() function available in chaiscript and also registers it as a user_type
but the return type for what() is defined as const char* and it seems that print(ex.what()) in Chaiscript only returns the first character of the exception text, not the full text
Jerry Smith
@dean1012
Jun 06 2017 01:18
hmm, it persists even if i add a new method to an existing class and declare it
something like: char *test() { return "Hello"; } will result in print(obj.test()) returning just 'H'
Does Chaiscript not support char * style strings?
Changing return type in my test method to std::string works flawlessly. I can work around this no problem. This could either be a bug or lack of functionality though
I'm going to work around this by creating an exception class based off std::string but since std::string itself can throw exception it isn't the most safe thing so I'd appreciate your input anyways
Jerry Smith
@dean1012
Jun 06 2017 01:26
On the ChaiScript side, I tried both print and puts and also tried encapsulating the ex.what() call inside a to_string. all had the same effect of only displaying first character
Jason Turner
@lefticus
Jun 06 2017 01:30
Ok, I'm building up a test, hopefully it will be helpful
Jerry Smith
@dean1012
Jun 06 2017 01:31
Thank you. I know the exception part itself is working fine now. I've tested that it's only catching the exception I want and not others
I just can't get it to print out the contents of char *
Jason Turner
@lefticus
Jun 06 2017 01:32
and you are throwing the Boxed_Value version?
Jerry Smith
@dean1012
Jun 06 2017 01:32
Correct. I tested the char * issue separately from exceptions though
Jason Turner
@lefticus
Jun 06 2017 01:32
right
Ok, I'm playing with a few things, I need to personally fully understand what I'm looking at
Jerry Smith
@dean1012
Jun 06 2017 01:33
chai::Boxed_Value(MyException) worked great though
I didn't know about that feature so thanks a lot
I can make a quick code sample if you'd like. You don't have to do more work than needed if you don't want to.
Jason Turner
@lefticus
Jun 06 2017 01:34
I'm adding a test to make sure
but what's funny is that I'm not having to do the throw Boxed_Value() myself. The typing is working out properly
so I'm going to push this test up and see what you think of it
Jerry Smith
@dean1012
Jun 06 2017 01:34
ok
Jason Turner
@lefticus
Jun 06 2017 01:37
I think the key that was missing from your example (but the gist is missing now) was the base_class relationship: ChaiScript/ChaiScript@76c7712
the base_class uses RTTI to support upcasting or downcasting of the types
anyhow, see what you think
Jerry Smith
@dean1012
Jun 06 2017 01:39
Sorry I deleted the gist and closed the issue since it didn't appear to be a bug per se. I'm looking at your link now
Jason Turner
@lefticus
Jun 06 2017 01:39
also tying it together with the base class will give you an appropriate what() for free
Jerry Smith
@dean1012
Jun 06 2017 01:41
it may have been the base_class missing. let me insert that into my code and remove boxed_value and see what happens
Jason Turner
@lefticus
Jun 06 2017 01:43
ok, and if you still get an issue, I would like to see that gist and see what I can find
Jerry Smith
@dean1012
Jun 06 2017 01:51
Ok the exception issue is fixed without Boxed_Value now. Adding the base_class binding was enough. Apparently that isn't handled by add_class
Nothing related to exceptions
I think that code sample should compile and run as-is
Jason Turner
@lefticus
Jun 06 2017 01:53
I actually am surprised that compiles at all, doesn't that have to be const char *?
but regardless, there's no way for chaiscript to know if you mean a pointer to a single char or a pointer to a string of chars
so we say it's a pointer to a single thing
if you really want a string, you'll have to return a std::string
Jerry Smith
@dean1012
Jun 06 2017 01:54
I see that's fine. It isn't bothering me at the moment. I just wanted to let you know of it. That makes sense though
I do want to thank you for making ChaiScript before I get back to work. I found your project after having difficulty integrating Lua
Jason Turner
@lefticus
Jun 06 2017 01:54
glad you like it
Jerry Smith
@dean1012
Jun 06 2017 01:55
I've yet to see if the scripting language itself is up to the task but it certainly seems like it and it's definitely the easiest to integrate with C++ that I've seen personally
Jason Turner
@lefticus
Jun 06 2017 01:56
if you do find yourself looking back at Lua, look at Sol2, which also has a gitter channel https://gitter.im/chat-sol2/Lobby
it's a very solid C++ binding for Lua, but it cannot have quite the same level of integration with C++, since it is still Lua underneath
Jerry Smith
@dean1012
Jun 06 2017 02:06
I appreciate it. I think this will work nicely for the time being though.
Jerry Smith
@dean1012
Jun 06 2017 02:54
Is ChaiScript close enough to JavaScript for syntax highlighting to be useful?
Jason Turner
@lefticus
Jun 06 2017 03:08
yes, with a couple of minor tweaks
Several editors do have ChaiScript support though - which one are you using?
Jerry Smith
@dean1012
Jun 06 2017 03:09
I'm using Visual Studio 2017. The Syntax Highlighting Pack extension comes with support for JavaScript (but not Chaiscript) but seems to be based on file extension so I can just name my scripts .js instead of .chai
I put an issue in on their tracker asking for support for your language though
Jason Turner
@lefticus
Jun 06 2017 03:11
Cool
When I'm making a highlighter I start with javascript and tweak some keywords and that's generally good enough
Jerry Smith
@dean1012
Jun 06 2017 03:20
Thanks. It works fine under Visual Studio with the exception it complains about semi colons but it's just warnings I can ignore
Jerry Smith
@dean1012
Jun 06 2017 03:34
I travel all the time. If I find myself around Denver I'll let you know. Maybe I can get your dinner as a thanks for your help :)
Jerry Smith
@dean1012
Jun 06 2017 05:14
I have two questions that may or may not be related... 1) Is it possible to include one Chaiscript from another to gain access to functions and whatnot defined in the other script? and 2) Is it possible to run another Chaiscript file from within a Chaiscript file?
Jason Turner
@lefticus
Jun 06 2017 14:44
These are the options for script evaluation from inside of script: https://github.com/ChaiScript/ChaiScript/blob/develop/cheatsheet.md#evaluation
maybe they have what you need?
Jerry Smith
@dean1012
Jun 06 2017 20:04
Yeah I saw that before I asked but use() didn't work inside chaiscript it complained of unknown function or something. I was able to make it work by exposing chaiscript::chai::use explicitly though
Jason Turner
@lefticus
Jun 06 2017 20:05
That's really odd, since I use use in all of my unit tests
Jerry Smith
@dean1012
Jun 06 2017 20:06
I'll throw my program up right now and test again, minus the exposure
Yes the error is "Can not find object: use"
The line in the chaiscript file is:
use("include_test_2.chai")
Jason Turner
@lefticus
Jun 06 2017 20:08
that's so odd
Jerry Smith
@dean1012
Jun 06 2017 20:08
so am I using use wrong?
Jason Turner
@lefticus
Jun 06 2017 20:08
I wonder why
where you the one who posted a bug about this a few weeks ago?
Jerry Smith
@dean1012
Jun 06 2017 20:09
I'm afraid not. I just start using Chaiscript a couple of days ago :)
I could just be special I suppose
Jason Turner
@lefticus
Jun 06 2017 20:09
ok, I need to know what's going on with it. you're at least the second person
Jerry Smith
@dean1012
Jun 06 2017 20:09
it works great if I do: chai.add(chaiscript::fun(&chaiscript::ChaiScript::use, &chai), "use");
If you want, I can zip up my whole visual studio project and send your way as is right now
Jason Turner
@lefticus
Jun 06 2017 20:10
are you on develop or on v6.0.0 ?
Jerry Smith
@dean1012
Jun 06 2017 20:10
I'm using official v6.0.0
Jason Turner
@lefticus
Jun 06 2017 20:10
ok, you don't need to send me a project this should be easy enough to figure out
Jerry Smith
@dean1012
Jun 06 2017 20:11
I literally just have two chaiscript files. each one contains a simple print() and the first one contains a use() to the second
so the output should be "this is file1" then "this is file2"
Jason Turner
@lefticus
Jun 06 2017 20:12
ok, I do need one thing: show me how you are constructing your ChaiScript object
Jerry Smith
@dean1012
Jun 06 2017 20:12
chaiscript::ChaiScript chai;
Jason Turner
@lefticus
Jun 06 2017 20:16
ok
Jerry Smith
@dean1012
Jun 06 2017 20:17
I noticed there are a few different ways to construct the object but I haven't found a reason (yet) to use anything more complex
Jason Turner
@lefticus
Jun 06 2017 20:20
that should do the right thing, but it would appear that somehow an option is being set that's preventing the use function from being exposed
Jerry Smith
@dean1012
Jun 06 2017 20:20
If you want me to try a different construction method, just provide it to me. I'll copy/paste in and report back
Jason Turner
@lefticus
Jun 06 2017 20:21
I'm tracing through it right now
Jason Turner
@lefticus
Jun 06 2017 20:38
Ok, I can reproduce it here, still not sure why. I'll figure it out though
Jerry Smith
@dean1012
Jun 06 2017 20:39
That's fine. At least you can reproduce it :)
Jerry Smith
@dean1012
Jun 06 2017 20:50
The constructor throws a compile error saying the argument can't be converted from ModulePtr to std::vector
Jason Turner
@lefticus
Jun 06 2017 20:51
oh yeah those examples need to get updated for v6.0.0
Jerry Smith
@dean1012
Jun 06 2017 20:52
That's fine. I was just trying to use a different constructor to see if that may illuminate the problem more
Jason Turner
@lefticus
Jun 06 2017 20:59
ChaiScript/ChaiScript@36e61de
that fixes the issue
Jerry Smith
@dean1012
Jun 06 2017 21:00
I'll take a look. I'll be honest, development isn't my line of work and I'm fairly inexperienced at unit testing and CI but why didn't your testing cover it? seems you do a pretty good job :)
I can confirm that fixed it for me.
use, eval_file, etc... all work
Jason Turner
@lefticus
Jun 06 2017 21:05
I try have tests for everything, but sometimes things get overlooked
so I try to add a test every time I see a bug, to make sure I don't reintroduce that bug later
Jerry Smith
@dean1012
Jun 06 2017 21:08
That's good thinking
I'm a Linux SysAdmin. I just program for fun, nothing serious.
Jason Turner
@lefticus
Jun 06 2017 21:10
Ah
yeah, so this particular issue now has a test for it
Jerry Smith
@dean1012
Jun 06 2017 21:14
As a question of curiosity, is there a recommended way to protect chai scripts from being easily viewed or edited once distributed? For example, I know Lua scripts can be compiled and then interpreted that way at runtime
Jason Turner
@lefticus
Jun 06 2017 21:18
No, there's no way to compile or obfuscate ChaiScript scripts
Jerry Smith
@dean1012
Jun 06 2017 21:19
Ok that's fine for me. As I said, a matter of curiosity. Thanks again
Jason Turner
@lefticus
Jun 06 2017 21:19
np