These are chat archives for ChaiScript/ChaiScript

15th
Jan 2017
Martin Chang
@marty1885
Jan 15 2017 01:20 UTC
Yes, you need to do f = chai.eval<std::function<void(int)>>("foo"); to have the most recent definition of foo.
Also, be aware that by calling ChaiScript.set_state(), the entire state of the interpolator will be reset., thus the all global variable's value will be reset to the value when the state is stored.
Martin Chang
@marty1885
Jan 15 2017 01:25 UTC
You will need to retrieve the value manually before calling `ChaiScript.set_state() then set the value after reseting.
Raoul Wols
@rwols
Jan 15 2017 01:26 UTC
okay, so I'd really have no intention of using set_state()
Martin Chang
@marty1885
Jan 15 2017 01:32 UTC
I found a way to do it lazily.
chai.eval(R"(def getFoo(){return foo();})");
auto f = chai.eval<std::function<int(void)>>("getFoo");
int val = f();//This will call the most recent definition of foo()
Ok, cool
Raoul Wols
@rwols
Jan 15 2017 01:33 UTC
Haha yeah, but that's essentially the same thing just a little less verbose in some places :smile:
Martin Chang
@marty1885
Jan 15 2017 01:34 UTC
LOL, true.
Raoul Wols
@rwols
Jan 15 2017 01:34 UTC
So I'm just gonna drop some more questions if nobody minds
What's the status on coroutines? Can ChaiScript do coroutines?
Martin Chang
@marty1885
Jan 15 2017 01:34 UTC
Just out of curious, what are you planning on using ChaiScript for?
Raoul Wols
@rwols
Jan 15 2017 01:35 UTC
Well I have this hobby game engine project and I need a scripting language for it
I'm trying to weigh the pro's and con's between python and chaiscript
there's also google's V8, but I feel that would be too much work to integrate
I have some experience with pybind11 and that works great
Martin Chang
@marty1885
Jan 15 2017 01:41 UTC
I don't think ChaiScript support coroutines since it's a minimal scripting language. And since most of it's feature comes directly from C++ and standard C++ does not support coroutines.
I don't think ChaiScript has support for it.
Raoul Wols
@rwols
Jan 15 2017 01:44 UTC
well there's boost.coroutine2, so that could be exposed to chaiscript
Martin Chang
@marty1885
Jan 15 2017 01:46 UTC
Maybe try Lua? I believe Lua and LuaJIT has basically the same API. It could run way faster than both Python and ChaiScript. (Tho the API is C only and using Lua as an OOP language is a bit awkward)
Raoul Wols
@rwols
Jan 15 2017 01:47 UTC
at this point I don't really care much about speed honestly
Martin Chang
@marty1885
Jan 15 2017 01:47 UTC
Surly that's doable. But it's not supported by default. You need to implement it your self.
Raoul Wols
@rwols
Jan 15 2017 01:48 UTC
I tried Lua and it's alright
I don't like exposing my functions to Lua though, because there is so much boilerplate
Martin Chang
@marty1885
Jan 15 2017 01:49 UTC
I'm also finding a scripting language for my graphics engine too.
Raoul Wols
@rwols
Jan 15 2017 01:50 UTC
then there's this "virtual stack" for Lua and it's a burden to keep dealing with that in my head
Martin Chang
@marty1885
Jan 15 2017 01:50 UTC
But performance is critical for me. My engine is eating up too much resources.
Raoul Wols
@rwols
Jan 15 2017 01:51 UTC
I see
Martin Chang
@marty1885
Jan 15 2017 01:51 UTC
That totally true.
I'll recommend ChaiScript if you are going for ease to use and not planning on using APIs besides what you have in your engine.
Else I'll suggest Python.
Raoul Wols
@rwols
Jan 15 2017 01:55 UTC
i don't expect the embedded script interpreter to be the bottleneck
rather it's going to be physics or shaders, so i'm not gonna worry about the speed of the language
Martin Chang
@marty1885
Jan 15 2017 01:56 UTC
I'm not talking about speed now. I'm taking about the pro and cons.
Raoul Wols
@rwols
Jan 15 2017 01:56 UTC
right
Martin Chang
@marty1885
Jan 15 2017 01:58 UTC
ChaiScript is designed to have the programmer to extend it's functionality. Thus you have to provide most of the feature (file IO, date and time, data streams, etc)
On the other hand, Python provides a ton of feature by it self. You can load meshes and even convert file formats within python.
Raoul Wols
@rwols
Jan 15 2017 02:00 UTC
i don't think python's standard library has that functionality
but "there's a module for that", as they say
you're right, python has a lot more to offer, i'm aware of that
Martin Chang
@marty1885
Jan 15 2017 02:12 UTC
Ohh... My fault.
Raoul Wols
@rwols
Jan 15 2017 02:12 UTC
so how does OOP work in ChaiScript?
as I understand ChaiScript is rather prototypical in that I can add member variables to an instance of a class after it has been declared
Martin Chang
@marty1885
Jan 15 2017 02:21 UTC
If i recall it correctly. It internally uses a std::map to track all of it's variables/methods within a class.
I'm not 100% percent sure tho.
Raoul Wols
@rwols
Jan 15 2017 02:23 UTC
yes, but now let's say i have this in C++: struct X { void f() = 0; };
can i expose that to chaiscript?
perhaps i can do it like this: if in C++ it's struct X { void f() { /* empty /* };
then expose that to chai
and then perhaps provide X::f = fun() { print("Hello, world!") } in the chai file
but I'm not sure
Martin Chang
@marty1885
Jan 15 2017 02:33 UTC
I don't think that's doable. you might have to call the function manually. (some template trick might help, but you have to call chaiscript manually to execute it)