Noob question using XCode


#1

Hi,
I am trying to use ChaiScript in a cocos2d-x project in XCode.
I download the source, add the folder containing the source to my project, and change the header search path for the project to include the folders I think it needs
/Users/maxxx/Documents/Projects/ChaiScript/ChaiScript/include/** /Users/maxxx/Documents/Projects/ChaiScript/ChaiScript/include/chaiscript

If I try to build using angle brackets it fails but change it to quotes and it builds

But when I run, I get a runtime error as it can’t find the stdLib moduls

So I am guessing I need to tell it to build that module - but I haven’t a clue how in XCode …

Update: I took the second example from https://github.com/ChaiScript/ChaiScript and got it running for IOS (but running the Mac build fails because it can’t find the hpp files - weird!)

So I can get it to work…

But I can only get it to call global C++ functions not class methods

So

  chaiscript::ChaiScript chai(chaiscript::Std_Lib::library());
    chai.add(chaiscript::fun(&test), "test");
    
    double d = chai.eval<double>("test();");

worlks

but

chaiscript::ChaiScript chai(chaiscript::Std_Lib::library());
chai.add(chaiscript::fun(&HelloWorld::test), "test");

double d = chai.eval<double>("test();");

doesn’t
I feel I am sooooo close!

** EDIT - now running on IOS and Mac - but same issue that cannot access class method frowning

** EDIT - works fine with a static class - which kinda makes sense!!!


#2

I was out at CppCon, but it looks like you got it going now?

If you want to call a method of a class, you have to pass it an object just like you would have to do in C++.

Something like the following would work:

chai.add(chaiscript::fun(&HelloWorld::someMethod), "someMethod");

HelloWorld hw;
chai.add(chaiscript::var(&hw), "hw");

double d = chai.eval<double>("hw.test();");

#3

That was the bit I was missing!

It’s simple when you know how!

Thanks for your help.