These are chat archives for ChaiScript/ChaiScript

28th
Nov 2017
Ricky
@shockdot
Nov 28 2017 08:10

Hi came across ChaiScript while looking into LUA... I have no scripting background what so ever, so looking at LUA... Was kind of like a nightmare. Then I found ChaiScript and a sudden rush of relief came over me, seriously. I mean so far I've only made the HelloWorld example, and built a Wrapper class for ChaiScript... but that took me like 10 minutes (if that). Where as with LUA, I still didn't have a working example. Great job, love it! I do have 3 questions though....

1) I will be calling Scripts from within objects in my C++ code, is there any way that I can inform the script of the object that called it... For example, say I had a Monster object execute the Script. Then from within the script, I want to be able to call C++ functions that get properties for the Monster, so I need a way to access the right monster... If worse comes to worse, I could just pass in the ID of the monster and call a function on the collection of monsters instead (if we can pass in values).

2) Correct me if I'm wrong here, but calling eval_file loads in the script every time right? So if for example I run the script 9000 times (kill 9000 monsters, run a script each time) the script gets loaded and executed 9000 times. Is there anyway to load it in once, and just execute it 9000 times?

3) Out of curiosity, has ChaiScript been used on an MMORPG in the past (or anything on that scale). I'm asking because I'd like to know what their opinions were on the performance aspect of things. (We can't have threads tied up calling script functions for long periods of times)

Jason Turner
@lefticus
Nov 28 2017 16:16
eval_file does evaluate the entire script when it is called. The best thing to do would be to have eval_file return a function that is reusable, then call that function for each kill in your example
I don't know if ChaiScript has been used in any large scale game - generally people use ChaiScript without telling me how they are using it @shockdot
and back to question 1) really the best way to work with chaiscript is by passing function objects around. Generate a function in script and return it back to C++ or make a function in C++ and hand it off to script
Tomasz Frydrych
@ksanderon
Nov 28 2017 16:25
If you have different script contexts for each monster object you, could easely bind methods of that monster( c++ class) to monster pointer in ctor and functions created this way add to context environment. If you need script language but still need performance, then chaiscript (or even lua or squirrel) is probably not best choice - better will be something with real jit implementation so for example v8, which integration with c++ is not so hard and well documented.
i suppose chai most important feature is that is is very easy to start with embeding.