Problem with adding struct and overload function


#1

Hi

I am new to chaiscript…And this is my first project

I wanted to add Vector3 datatype to chaiscript and also.wanted to use overload function …
I followed the steps from the docs to try and impliment it … But i get a few errors while compiling in VS2013 Update 4

#include<iostream>
#include"Header.h"

using namespace std;
using namespace chaiscript;

std::string helloWorld(const std::string &t_name)
{
    return "Hello " + t_name + "!";
}
void Update()
{
    cout << "Hai";
}


// Test structure for passsing and communicating
struct Vector3
{
public:
    float x, y, z;

    Vector3(float X, float Y, float Z)
    {
        x = X;
        y = Y;
        z = Z;

    }


    inline  Vector3 operator+(const Vector3& b)
    {
        Vector3 Res(0, 0, 0);

        Res.x = x + b.x;
        Res.y = y + b.y;
        Res.z = z + b.z;

        return Res;
    }
};

// operator overloading 
void PrintVec(Vector3 vec)
{
    cout << vec.x  << " " << vec.y << " " << vec.z << endl;
}

// Overloading function to add two Vector3's
Vector3 Add(Vector3 &a, Vector3& b)
{
    Vector3 Res(0,0,0);
   return a + b;
}

// Test Class 
class Test
{
public:
    void Overloadable();

};

int main()
{

    chaiscript::ChaiScript chai(chaiscript::Std_Lib::library());
    
    // add all vaiables and function 
    chai.add(chaiscript::fun(&helloWorld),
        "helloWorld");
   
    chai.add(chaiscript::user_type<Vector3>(), "Vector3");                                   // Add a struct type
    chai.add(chaiscript::constructor<Vector3(float, float, float)>(), "Vector3");            // Constructor
    
    chai.add(chaiscript::fun(&Vector3::x), "x");                                             // Varaibles
    chai.add(chaiscript::fun(&Vector3::y), "y");
    chai.add(chaiscript::fun(&Vector3::z), "z");

    // operators
    chai.add(chaiscript::fun(&Vector3::operator+), "+");
    chai.add(chaiscript::fun(&Add),"Add");
    chai.add(chaiscript::fun<void (Test::*)()> ((&Test::Overloadable)), "OverloadFunction" ); // Add a overload function
    chai.add(chaiscript::fun(&Update), "Update");
    chai.add(chaiscript::fun(&PrintVec), "PrintVec");
    // Slelct and evaluate file
    chai.eval_file("Script.chs");

    cout <<

        system("PAUSE");
    return 0;
}

Errors

Error	2	error C2027: use of undefined type 'std::_Get_function_impl<_Fty>'	
Error	4	error C2027: use of undefined type 'std::_Get_function_impl<_Fty>'	
Error	5	error C2146: syntax error : missing ';' before identifier '_Mybase'	

Error	1	error C2244: 'chaiscript::fun' : unable to match function definition to an existing declaration		

error C2504: 'type' : base class undefined	
Error	6	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Cannot register overloaded member function
#2

Use this syntax instead:

chai.add(chaiscript::fun(static_cast<void (Test::*)()>(&Test::Overloadable)), "OverloadFunction" ); // Add a overload function

I recently changed some of the code for determining the type of an object passed to fun and may have broken some cases that used to work.

Please show me if you got that from an official example so I can either fix ChaiScript or the example.

(The changes resulted in significantly faster and smaller builds, so I don’t regret breaking something like that)