ChaiScript is the first and only scripting language designed from the ground up with C++ compatibility in mind. It is an ECMAScript-inspired, embedded functional-like language.
ChaiScript is licensed under the BSD license.
ChaiScript is the first and only scripting language designed from the ground up with C++ compatibility in mind. It is an ECMAScript-inspired, embedded functional-like language.
ChaiScript is licensed under the BSD license.
No bad post, write more
Thanks for the bug report. Reading over the source code it appears to me that the problem is that set_state() does not call sync_cache() ( a function which is normally called during any eval() operation ). I'll verify and test a fix as soon as I can get to it.
-Jason
It would be great if you could submit a bug report with complete source (both C++ and chaiscript) that demonstrate the memory leak so we can check into it.
Thanks.
Jason
Who thought it was a good idea to give me admin privs? Sorry about that.
and in chaiscript:
Probably the best way to get a "global variable" is to not make it a literal variable. Instead register a getter and setter for the variable you want to be globally visible. These functions will be global, so it's up to you to maintain thread-safety, but it will be visible to all threads.
===
oops, someone edited my post instead of reply.
Thanks, that works so far.
My new problem, taking the code from above as base:
User Input: "var i = 3"
Call : ResetState()
User Input: "return i" - returns 3
I would have expected "i" to not exist anymore.
Then i tryed the following:
That will throw an exeption as soon ResetState() is called.
Edit:
I read your statement about avoiding global vars and using functions instead. That makes perfectly sense and everything is working as intended now, as functions are reset properly.
Edit 2:
I found a memory leak
What happens?
case 1: if calling eval EVERY loop, memory usage is low, nothing is leaking
case 2: if calling eval NEVER , memory usage keeps raising, here is the leak.
case 3: if calling eval CONSTANTLY each 10th loop, memory usage is higher than in case1, but seems not to leak any further
case 4: get´s complicated to explain. each time, ResetState() is Called without calling eval afterwards, memory usage will go up.
for example after 10 times ResetState(), i am calling RunFile() or whatever involves eval. After this eval, i can again call ResetState() 10 times, without increasing the memory usage. but as soon as it get´s called the 11th..... time without eval intetween memory usage will go up again.
commenting out either the set_state or add will stop this strange behaviour. but will also break my way of updating important pointers.
I solved it, by calling eval("") at the end of my Reset function.
But it doesn´t feel like beeing the proper solution...
In ChaiScript there aren't global variables. You can register a constant value in your C++ application that is global, but you can't make a variable that all functions can see.
If you're curious why:
The short answer is that global variables aren't good practice.
The long answer is that we liked the idea of reusable functions in ChaiScript. The easiest way to make reusable functions is to always have a function's parameters be explicit, so you can just call it from any context and know you're passing in everything it needs.
The even longer answer is that ChaiScript is automatically thread-safe. If you take the same engine and call scripts in different threads, this should, in theory, "just work". Having global variables makes this automatic safety difficult and the implementation hairy (since now some variables would be handled differently than others).
shouldn't `foo` be a global variable that can be resolved inside barfunc(), so calling barfunc() prints "100", too?
is this the intended behavior?
We've implemented a fix that solves the naming conflict problem you were having. Don't forget to also properly initialize your members in your constructors. Since members are not typed we have no way of initializing them for your.
I really would have expected your example to work. It seems I'm wrong, however.
You can force the issue by telling ChaiScript exactly what type you want to work with:
You seem to be bubbling up the question of handling derived types, something that we have avoided up until now. We'll see what's possible.
-Jason
I've started lurking on #chaiscript on freenode for anyone who happens to want to stop by. I've also registered with freenode to officially be a group, but they say registrations take a while to process.
-Jason
I'll look into it this evening, not sure why you would have a problem with that one.
How can i expose their functions to chaiscript?
get().Print2() works fine
get().Print1() does not - "No matching function to dispatch to" during evaluation at (1, 7)"
Your error is something of a red herring, the actual problem is that the local variables for an object type and the parameter names for the constructor are conflicting.
The above should work for you. We will see about fixing the scope problem so that this lookup/naming problem doesn't catch other people, (and should probably fix that error you are getting, to something more reasonable too).
I'll look into the IRC channel, might be hard for the main developers to keep up with, but we'll see if we can't give it a shot.
-Jason
My first question is why do I get this error: "No matching function to dispatch to" on the last line when trying to compile:
My second question is more of an inquiry. What other language features do you plan to add?
Lastly, my suggestion. There should be an IRC chat room! :-)
This one is fixed too, in the newly released 2.3.2.
Hey, when you define CHAISCRIPT_NO_THREADS the code will fail to compile under MSVC. This is due to '#warning' not being a valid preprocessor command.
I'm not sure what the equivalent is, but "#pragma message("Blah")" will print a message to the output window, so that's kind-of an alternative.
At any rate, you need to disable the use of "#warning" on MSVC or it will fail to compile. :)
Thanks.
Thanks.
As I said though, you could've kept the specialization by simply marking it as inline. That would stop the linker errors.
Why did you decide to instead pull the specialization? I'm not questioning your decision, as obviously you're the expert when it comes to the implementation of ChaiScript, I'm just curious..
That's actually not a bad suggestion...
Thanks, I'll give that a try, and if it doesn't work I'll try to get together some basic code to try and reproduce it. It may be a little while though as I'm relocating to a different country quite soon so most of my time is spent preparing that.
Thanks again, hopefully that's the issue, and if it is, I might even be able to work out a fix.
You're getting outside of my knowledge for windows programming, so I'm something at a loss a to how to help you with this one, unless you can provide a succinct example to reproduce the problem.
That said however, I'm guessing that your problems stem from our automatic thread context handling which is based on a static thread local storage objects.
If that's the case, you may be able to work around it by compiling with CHAISCRIPT_NO_THREADS, which I'm guessing IS an option for you, since you had swapped lua out for ChaiScript.
Let me know if this helps at all.
Fixed and fixed.
These two problems were generic to all compilers, took me a few minutes to track down the second one, and I just removed the std::swap specialization. I'm still a little confused about that one, since it was written as a template specialization, not just as an overload.
Oh well.
Hey, I think I have indeed found another issue with ChaiScript (unless I'm missing something).
My project makes use of quite a few DLLs, and about 3 of those DLLs need to have access to ChaiScript. Previously when I was using Lua and LuaBind in a similar situation, I simply passed around a pointer to the LuaBind instance (or rather, a class containing that instance, along with some extra data).
However, when I try to do that with ChaiScript I'm getting some very nasty access violations.
The problem manifests itself in two situations:
1. When I use a global ChaiScript object (i.e. static) that is NOT function local. The reason it matters whether it's function local is that the problem seems to manifest itself when the object is created "too early". The problem manifests itself when ChaiScript is created too early, I don't know what "too early" exactly is, I just know that if I defer creation of the ChaiScript object until first use, there is no problem. I can do this by either using a pointer to the ChaiScript instance and allocating it at first use, or using a local static instance.
2. Above, I noted that if I allocate the ChaiScript instance at first use, then the problem goes away. This is true, but only if the module using the object is the one that allocated it. As soon as I give the pointer to another module to use, I get the access violation again. I am compiling all modules with the same settings, so that should not be an issue, and that worked fine when I used to use LuaBind...
I'm happy to provide more information and sample code if necessary. Right now I have no idea what's going on.
Also, I should mention, the two errors I outlined above are fairly minor. This one however is critical. If I can't work out how to fix this I don't think I'm going to be able to use ChaiScript, which would be extremely unfortunate as I've grown quite accustomed to it in my (albeit short) use of it. So, help with this matter would be greatly appreciated.
Thanks.
P.S. I don't know whether this is relevant, but if you're trying to reproduce this error, you may need to know that my DLLs are not loaded 'normally'. They are 'injected' into another application. This in itself should not cause any issues though, because I'm making sure to do it safely. (I'm avoiding any potential problems which may be caused by doing anything dangerous in DllMain, by doing NOTHING in DLLMain, and opting instead to use a named export which is called once the module is fully loaded, hence making it safe to allocate any resources I want/need.)
In boxed_value.hpp, you specialize std::swap. Under VC10, if Chaiscript's headers are included in more than one translation unit, the template specialization causes linker errors due to a redefinition of an existing function. A fix is to simply mark the function as 'inline'. Unfortunately I don't know if the standard permits you to do that, or what the exact rules are for specializing std::swap, so I'll leave that up to you. However I assume that would be a legitimate fix, as typically defining functions in header files means you need to mark them as inline or for them to be templates in order to avoid linker errors.
The second is that if Boost.Signals2 has its headers included AFTER ChaiScripts, then you will get compiler errors.
To work around this (because I use Boost.Signals2 in my application), I simply make sure to always include Signal2's headers before ChaiScript's. I'm not sure of the actual problem here, so again, I can't really give you a solution and I'll leave that for you to decide.
Sorry to be a pain. :(
Thanks for being so helpful though.
P.S. There's one more potential issue I'm investigating, but it's hard to reproduce and I'm not even sure yet if it's my fault or ChaiScript's fault. If it's an actual issue I'll post again with more info, otherwise don't worry about it, it's probably a non-issue.
We are looking for projects to put in our new project gallery, if you provide some details we will probably add your project as well (you can use the contact us link if you would like).