About ChaiScript

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.

Download

Version: 2.3.3 Released: 5/15/2010

Source
Windows
Linux

ChaiScript Questions

Any questions related to using ChaiScript

Is it possible to access native types from C++

Hello again.

I want my users to be able to create types with chaiscript and for me to be able to retrieve the type information - mainly the attribute information.

Is it in any way possible?

Also is it at all possible to force a var or attribute to be of a certain type (strong typing)?

Thanks
Sebastian

yes, dynamic objects can be shared

There are a variety of techniques that can be used to share data between chaiscript defined objects and C++. I've just checked in a unit test to verify that it all worked, and provide some examples.

Regarding forcing a variable to be a certain type or not, let's start by clarifying terminology. Hopefully I have this right, but ChaiScript is a strongly typed dynamic language. The variable type is determined at runtime, but once it is set, it is set permanently. There are very few automatic type conversions. Conversions between pointer, reference, const, boost::shared_ptr happen automatically, whenever they safely can. Pointers that would require modifying the underlying type (ie, int->float) do not happen automatically.

There is exactly one type of variable declaration in ChaiScript, the "var" that has its type set on the first assignment operation.

However, you can force something to be a certain type during a function call by using function guards, like:

fun test(x) : x.is_type(int_type) {
 
/* do something */
 
}

Hope that helps.

-Jason

I guess I can work with that

I looked into Dynamic_Object and it can satisfy most of my needs.

I'm looking to use chaiscript as a scripting language for a kind of a database engine.
And it would be useful to allow the user to create types using the standard mechanism and for me to be able to store data using those types. The Dynamic_Object will allow me to store the object and it's associated data.
However I have still to decide whether weak typing is good enough for me. If not this method will not allow for creating a schema that can be reused (How can you compare objects if every instance can store different type of data under the same attribute name?). It would have been best if during the creation of the type there was the option to decide which type each attribute will have before instantiating the object.
Like (formal):

Attribute Definition ::= "attr" class_name "::" attribute_name
                       | "attr" class_name "::" attribute_name type_name

And a sample:

attr Rectangle::Height int

If the user uses this notation then values assigned to Rectangle::Height will be converted to int if possible or an exception is thrown (or any other predictable behavior).

Unless you are willing to add this behavior I think I will still use chaiscript but I will produce a different mechanism for creating user defined types that can be stored in that database.

Thanks
Sebastian

I see your point

We designed ChaiScript foremost as a tool for tying together your C++ objects, and did not initially consider that you would want to define types in ChaiScript.

Then, as we got further along and decided to give types a try, we thought they should be in the spirit of the rest of ChaiScript and very free form. If you want something rigid, you should define it in C++, not in ChaiScript.

However, I see your point about wanting to create types that are passed back from ChaiScript land into C++ land.

Your proposal is interesting, but I don't think it would ultimately solve your problem, because the dynamically typed attr would still exist. The user could ignore that option and still make things dynamically typed.

Perhaps requiring the user to provide a typemap would work for you? This is something you could validate at runtime and perform any conversions that you wanted to based on what the user specified.

attr Rectangle::type_map
attr Rectangle::height
attr Rectangle::width
fun Rectangle::Rectangle() { this.type_map = ["height":int_type, "width":int_type]; }

This would make you do a little bit more heavy lifting, but by requiring the user to provide a type_map attribute, you could reject an object simply on its being missing. Then, you could further use the type_map as a driver to determine which attributes should get stored and how they should get stored.

This would allow the user even to use internal attributes for whatever purposes he has in mind, but will never get stored by your database tool.

I'm sure there are unanswered questions about the best way to extract/access/convert the stored data that we could help you with.

It's at least an idea, anyhow.

Just out of curiosity, is this a closed or open project? Is it something we would like to add to the list of projects using ChaiScript?

That is possible

I was thinking of using a type map in a little different way. How ever this still requires the user to specify the types in this way which is a little cumbersome and it has another problem still.
The main problem is that in this way the language and engine are not used to enforce any kind of value assignment correction. This is not a major problem since I can reject a variable using the type when it is used by the db engine if the values of attributes don't fit the specification or if there isn't a full map declared but it's less elegant and also it's a late check and it's always best to capture errors early. Also the user can later change the map without a problem and accidentally or deliberately force wrong value insertion (This can be avoided by an error check not just against the type but also against the type definition in the DB but that takes the error checking even further down the pipeline)

If you would add the option to specify the type of an attribute I was thinking in using it in one as follows:

Supply from C++ to Chaiscript a function called CreateType that will accept a type name and a map in the form you specified. This function will then create a Chaiscript block to define this type with the strong typing and register it with the db engine. This way the language and engine can be used to enforce the safety of assignments. And every time the db engine is loaded the type will be reloaded.

Another option will be to supply a RegisterType class that will work with the option you suggested but in that way we will not benefit from early error detection.
If you can support strong typing then at least the next time the db engine is loaded the type safety will be enforced.

So I see it's not a must have but for me it's a really really nice to have.

Is it hard to implement?

Thanks
Sebastian

Non extendable classes

First let me say thanks and Hello.

My question is whether there is a way of registering a class with chaiscript that cannot be further extended by a user script?

Thanks
Sebastian

No, this is not possible. In

No, this is not possible. In ChaiScript, technically, methods do not exist; only functions exist.

So, a method call like:

obj.somefunc();

Is translated to:

somefunc(obj);

So, fundamentally, the user will always be allowed to add functions that can operate on your class. This means that the method sugaring we perform essentially means that all classes are always extendable, inside of script.

Unless I miss your meaning. What affect are you going for? What is your use case?

I see your point

I understand the explanation and I agree it should not pose a problem. After looking through the docs again I can see that there is no implicit access to members I don't explicitly register so it's OK. I was really worried about users gaining access to protected or private members but I see it can't be so.

error with functor call

OK having that previous problem with variables I tryed to implement my function via functor call.
(so whole script is 1 function)

fun(meta,dicom)
{
  print(meta.srcAeTitle);
}

ProcessDES now looks like this

	boost::call_once(&g_chaiInit,g_chaiInitOnce);
 
	g_chai.functor<void(DcDirMetaInfo_ptr,DcElemList_ptr)>(des)(pMetaInfo,pElemList);

however I'm getting an exception/error when running this (at least its not a crash)

Unable to pop global stack

any idea why ??

Im thinking that both my

Im thinking that both my errors are caused by the same thing.
(like some portion of the stack is not being initialize)

any idea why is this

any idea why is this happening ?
and whay can i do to workaround it ?

Please post a bug report

It'd help if you could post all of your source files as a bug report to chaiscript.googlecode.com. This way I can try to reproduce the problem and see where the error is. I'll do my best to debug it this weekend, or maybe tomorrow afternoon.

Thanks!

Thanks for the bug report.

Thanks for the bug report. I've fixed the problem in SVN. You were correct that the stack was not being properly initialized in the case of adding objects to the stack from C++ during multithreading.

Crash

I'm getting crash when trying to add a shared_ptr<> variable (first variable)
to the chaiscript.

it seems like its accessing non exisiting index or element.

      void add_object(const std::string &name, const Boxed_Value &obj)
      {
        StackData &stack = get_stack_data();
        validate_object_name(name);
        stack.get<0>().erase(name);
        stack.get<1>().back()[name] = obj;
      }

it happens on last line of this method.

this is the setup (processDES can be called from multiple threads )

static chaiscript::ChaiScript g_chai;
static boost::once_flag g_chaiInitOnce = BOOST_ONCE_INIT;
 
void g_chaiInit()
{
	g_chai.add(chaiscript::fun(&parseHex),"hex");
	g_chai.add(chaiscript::fun(&getTagValue),"getTag");
	g_chai.add(chaiscript::fun(&setTagValue),"setTag");
}
 
void processDES(DcDirMetaInfo_ptr pMetaInfo,DcElemList_ptr pElemList,const string& des)
{	
	boost::call_once(&g_chaiInit,g_chaiInitOnce);
 
	g_chai.add(chaiscript::var(pElemList),"dicom"); // This is the call that crashes in add_object
	g_chai.add(chaiscript::var(pMetaInfo),"meta");
 
	g_chai.eval(des);	
}

any ideas ?

Standard Math Library?

yet another question. Is there a standard math library ready to be included? For time to time functions like sin, cos, exp .... just come handy.
And a related question, is there any way to specify 1.0e-6 as a double (without typing 0.000001) ?

Number representations

To my memory, there aren't yet ways to do number literals like you describe, though it shouldn't be too difficult to support them.

Performance

Hi there , I love ChaiScript! But, will it see some performance boosts in the future?
Especially for-loops (C-style) seems to be very slow.

Performance and flexibility

In ChaiScript, we intentionally focused on flexibility over performance. Why? Let's think about how you might use a scripting language in a C++ application:

You build up your C++ app, but realize parts should be runtime configurable. These types of things might be settings, business logic, or game scripts.

These call back into the engine to fire off the events or set the values for you. The script itself is merely a set of calls back to the main application.

In ChaiScript, we went one step further. The entire script is calls back to the ChaiScript engine and your application. Every addition, every step of the loop, is all calling back to ChaiScript. This makes it generally less performant, but in return you get the ability to augment what each script does to the nth degree.

We chose to put less restrictions on the programmer. We could have tightened things down and prevented that level of modification, and for our efforts we might have gotten something of a speed increase, but in our opinion, if you're using ChaiScript for time critical things, you're using it wrong. Put the time critical sections in C++ where they will always work best, and fire them off from your script.

Hope that helps.

troubles with binding

Hi there! I like ChaiScript - it's really comfortable way to bind functions in scripts. But I have trouble with binding:
I'm trying to bind function (Irrlicht engine):

In code:

IAnimatedMesh* LoadAnimMesh(io::path path)
{
return smgr->getMesh(path);
}

In main():

ChaiScript chai;
chai.add(fun(&LoadAnimMesh),"LoadAnimMesh");
chai.eval_file("C:\\main.chai");

In main.chai:

var x = LoadAnimMesh("C:\man.b3d")

But, when I tried to run, I'm received unknown exception. Please, tell me, where the problem can be.
Thanks in advance.

Type on your main.chai

It would appear that you have a typo in your main.chai:

var x = LoadAnimMesh("C:\man.b3d")

should be:

var x = LoadAnimMesh("C:\\man.b3d")

Normal C++ escaping rules apply.

oh, such a stupid typo -_-

oh, such a stupid typo -_- facepalm.jpg. Thanks.

chaiscript and boost::signal

hi, i tried to get chaiscript working with boost::signal and ended with this implementation (subclass boost::signal and implement some extra stuff for chaiscript).
http://zoadian.pastebin.com/e0NPDZQZ
it works, but is there any better solution?
wasn't able to find anything about how to bind templateclass members.

Thanks,
-suicide

Looks good to me

We should post your example for others to look at. Using the template to help you register the signal functions is what we needed to do when exposing std container classes.

Unfortunately there is not (and cannot be) a more generic way of exposing templates because we need to know the function pointer address of the functions we want to call at compile time. The only way to know these addresses is to instantiate the templates that are being used, and get the functions from them, as you did.

The important thing to realize, as you did, is that a template member is just like any other function, you just have to be explicit about which instantiation of the template you are referring to.

-Jason

boost::signals within chaiscript

ok i cleaned it up a bit.
http://zoadian.pastebin.com/TX6MaPYt

any idea how to call the signal from within chaiscript?

in c++ it would be

  PSignal<void ()> sigUpdate;
  sigUpdate(); //call all connected slots. how to call it in chai?

post it as a example whereever you like ;)

my wish for next chai version: reduce compiletime (sourcefiles/lib)

thx, suicide

Re: emitting signal.

We don't have any support for operator() in chaiscript, which is an interesting point that I will make a note of.

You would want to do something like:

chai.add(fun(&PSignal<void ()>::operator(), "emit"));.

Then in your chaiscript you could emit the signal explicitly:

mysignal.emit()

I'll look more closely at your example as soon as I get more time and see if I cannot make any more suggestions.

I've been considering a set of optional libraries that ship with chaiscript, like the stl extra that is currently there. boost::regex and filesystem were also considerations. boost::signal might be a good one too. You're showing that it could be a great way of hooking together c++ and chaiscript.

Regarding compile time, just wait :).

In all seriousness, 95% of what we need to do cannot really be done in compiled library code, but there are some techniques for making recompiles of your application faster. I should publish some docs on that. The gist of it is that you want to include ChaiScript in your main.cpp, then have a mylib.cpp that creates and returns a chaiscript::module object. Your this way, main.cpp (and the core of chaiscript) only needs to be recompiled rarely, and you make all of your changes inside your mylib.cpp.

-Jason

variable scope

var foo = 100
def barfunc()
{
  print(foo)
}
print(foo) // prints "100"
barfunc() // Eval_error, Can not find object: foo.

shouldn't `foo` be a global variable that can be resolved inside barfunc(), so calling barfunc() prints "100", too?

is this the intended behavior?

Good question

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).

global variables

class GlobalVariableHelper
{
public:
  Boxed_Value & __get_global(std::string const & name)
  {
    // require read-lock for thread-safe
    return _M_globalvars[name];
  }
 
  void __set_global(std::string const & name, Boxed_Value & value)
  {
    // require write-lock for thread-safe
    __globalvars[name] = value;
  }
 
private:
  std::map< std::string, Boxed_Value > _M_globalvars;
}
 
...
GlobalVariableHelper gvhelper;
chai.add(fun(&GlobalVariableHelper::__get_global, gvhelper), "get_global");
chai.add(fun(&GlobalVariableHelper::__set_global, gvhelper), "set_global");

and in chaiscript:

set_global("foo", 100); // foo = 100;
set_global("foo", get_global("foo") + 10); // foo += 10

global variable

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.

My bad

Who thought it was a good idea to give me admin privs? Sorry about that.

How can i expose derived classes?

How can i expose their functions to chaiscript?

class Class1
{
public:
	Class1(){}
	virtual ~Class1(){};
	void Print1(){std::cout << "Print from Class1" << std::endl;}
};
 
class Class2 : public Class1
{
public:
	Class2(){}
	virtual ~Class2(){}
	void Print2(){std::cout << "Print from Class2" << std::endl;}
};
 
Class2 * pClass2 = new Class2;
 
Class2 * getClass2(void)
{
	return pClass2;
}
 
void init()
{
	Chai.add(fun(&Class2::Print1), "Print1");
	Chai.add(fun(&Class2::Print2), "Print2");
	Chai.add(fun(&getClass2),"get");
 
}

get().Print2() works fine
get().Print1() does not - "No matching function to dispatch to" during evaluation at (1, 7)"

that should work...

I'll look into it this evening, not sure why you would have a problem with that one.

Learn something new every day

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:

class Class1
{
public:
	Class1(){}
	virtual ~Class1(){};
	void Print1(){std::cout << "Print from Class1" << std::endl;}
};
 
class Class2 : public Class1
{
public:
	Class2(){}
	virtual ~Class2(){}
	void Print2(){std::cout << "Print from Class2" << std::endl;}
};
 
Class2 * pClass2 = new Class2;
 
Class2 * getClass2(void)
{
	return pClass2;
}
 
void init()
{
	Chai.add(fun<void (Class2 *)>(&Class2::Print1), "Print1");
	Chai.add(fun(&Class2::Print2), "Print2");
	Chai.add(fun(&getClass2),"get");
}

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

Stupid question: How does it work with parameters

Hi,

How does the above example work with the modification?

	void Print1(int value){std::cout << value<<" Print from Class1" << std::endl;}

It does not compile anymore after adding the parameter, showing the following error (MacOSX 10.6.4, gcc4.2 and gcc4.5):

/opt/local/include/boost/function/function_template.hpp: In static member function ‘static void boost::detail::function::function_void_mem_invoker1<MemberPtr, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with MemberPtr = void (Class1::*)(int), R = void, T0 = Class2*]’:
/opt/local/include/boost/function/function_template.hpp:913:   instantiated from ‘void boost::function1<R, T1>::assign_to(Functor) [with Functor = void (Class1::*)(int), R = void, T0 = Class2*]/opt/local/include/boost/function/function_template.hpp:722:   instantiated from ‘boost::function1<R, T1>::function1(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = void (Class1::*)(int), R = void, T0 = Class2*]/opt/local/include/boost/function/function_template.hpp:1064:   instantiated from ‘boost::function<R ()(T0)>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = void (Class1::*)(int), R = void, T0 = Class2*]’
test_inherit.cpp:31:   instantiated from here
/opt/local/include/boost/function/function_template.hpp:225: error: no match for call to ‘(boost::_mfi::mf1<void, Class1, int>) (Class2*&)/opt/local/include/boost/bind/mem_fn_template.hpp:163: note: candidates are: R boost::_mfi::mf1<R, T, A1>::operator()(T*, A1) const [with R = void, T = Class1, A1 = int]
/opt/local/include/boost/bind/mem_fn_template.hpp:184: note:                 R boost::_mfi::mf1<R, T, A1>::operator()(T&, A1) const [with R = void, T = Class1, A1 = int]

Inheritance vs. Not

Keep in mind that the above example is only necessary if you need to worry about choosing the specific version of an inherited member. If you are in that situation, you might do something like:

Chai.add(fun<void (Class2 *, int)>(&Class2::Print1), "Print1");

To solve that problem.

If the member is not inherited, you could just do (the recommended / ideal form):

Chai.add(fun(&Class2::Print1), "Print1");

thanks + new Problem

Thanks, that works so far.

My new problem, taking the code from above as base:

chaiscript::ChaiScript::State backupState;
void init()
{
	Chai.add(fun<void (Class2 *)>(&Class2::Print1), "Print1");
	Chai.add(fun(&Class2::Print2), "Print2");
	Chai.add(fun(&getClass2),"get");
        backupState = Chai.get_state()
}
 
void ResetState()
{
	Chai.set_state(backupState);
}

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:

chaiscript::ChaiScript pChai = new chaiscript::ChaiScript;
...
...
...
void ResetState()
{
        delete pChai;
        pChai = new chaiscript::ChaiScript;
	pChai->set_state(backupState);
}

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

void ResetState()
{
	pChai->set_state(backupState);
        pChai->add(fun(&getClass2),"get");
}
 
PseudoMain()
{
    	while(command != "quit")
	{
		for(int i = 0; i < 200; i++)  // just a little bit extra overhead
			pChai.ResetState();
 
		if(command == "gc")
			pChai.RunFile("Test.chai");
		command = get_next_command();
 
}

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...

Please log a bug report

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

Thanks for the bug report.

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

2 Questions and a Suggestion

My first question is why do I get this error: "No matching function to dispatch to" on the last line when trying to compile:

var kPI = 3.141592653589793
var kSolarMass = 4.0 * kPI * kPI
var kDaysPerYear = 365.24
var dt = 0.01
 
attr Vector3::x
attr Vector3::y
attr Vector3::z
def Vector3::Vector3(x, y, z) {
    this.x = x
    this.y = y
    this.z = z
}
 
def Vector3::`+`(rhs) {
    return Vector3(this.x + rhs.x, this.y + rhs.y, this.z + rhs.z)
}
 
def Vector3::`-`(rhs) {
    return Vector3(this.x - rhs.x, this.y - rhs.y, this.z - rhs.z)
}
 
def Vector3::`*`(rhs) {
    return Vector3(this.x * rhs, this.y * rhs, this.z * rhs)
}
 
def Vector3::Length() {
    return sqrt(this.x * this.x + this.y * this.y + this.z * this.z)
}
 
def Vector3::SquaredLength() {
    return (this.x * this.x + this.y * this.y + this.z * this.z)
}
 
attr Body::position
attr Body::velocity
attr Body::mass
def Body::Body() { }
def Body::Body(x, y, z, vx, vy, vz, mass) {
    this.position.x = x
    this.position.y = y
    this.position.z = z
    this.velocity.x = vx
    this.velocity.y = vy
    this.velocity.z = vz
    this.mass = mass
}
 
 
var sun = Body(0, 0, 0, 0, 0, 0, kSolarMass)

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! :-)

Fixed in r482

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.

Your error is something of a

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.

var kPI = 3.141592653589793
var kSolarMass = 4.0 * kPI * kPI
var kDaysPerYear = 365.24
var dt = 0.01
 
attr Vector3::x
attr Vector3::y
attr Vector3::z
def Vector3::Vector3(m_x, m_y, m_z) {
    this.x = m_x
    this.y = m_y
    this.z = m_z
}
 
def Vector3::`+`(rhs) {
    return Vector3(this.x + rhs.x, this.y + rhs.y, this.z + rhs.z)
}
 
def Vector3::`-`(rhs) {
    return Vector3(this.x - rhs.x, this.y - rhs.y, this.z - rhs.z)
}
 
def Vector3::`*`(rhs) {
    return Vector3(this.x * rhs, this.y * rhs, this.z * rhs)
}
 
def Vector3::Length() {
    return sqrt(this.x * this.x + this.y * this.y + this.z * this.z)
}
 
def Vector3::SquaredLength() {
    return (this.x * this.x + this.y * this.y + this.z * this.z)
}
 
attr Body::position
attr Body::velocity
attr Body::mass
def Body::Body() { }
def Body::Body(m_x, m_y, m_z, m_vx, m_vy, m_vz, m_mass) {
    this.position = Vector3(m_x, m_y, m_z)
    this.velocity = Vector3(m_vx, m_vy, m_vz)
    this.mass = m_mass
}
 
var sun = Body(0, 0, 0, 0, 0, 0, kSolarMass)

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

freenode

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

Fixed

This one is fixed too, in the newly released 2.3.2.

VC10 B2 Support?

Are there currently any plans to support compiling using VC10? The project I'm working on is currently utilizing VC10 so we can make use of C++0x features, and we wanted to use ChaiScript, but there are a slew of compiler errors (most of which seem to be cascading, but still...).

I took a quick look and was able to fix one or two, but I simply don't have enough knowledge about the implementation of ChaiScript to fix the rest, it would take me way too long to sit down and take in the implementation then work out what's going wrong.

VC10 support would be greatly appreciated, as going back to VC9 (aka VC 2008) is not really an option at the current time.

Thanks. Look forward to hearing from you.

MSVC Problem with Threading Disabled

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.

Some more VC10 B2 problems

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.

Fixed and fixed. These two

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.

Thanks. As I said though, you

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..

Followup

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.)

You're getting outside of my

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.