0

enter image description here

The error:

Error   C2664   'void chaiscript::detail::Dispatch_Engine::add(const chaiscript::Type_Info &,const std::string &)': cannot convert argument 1 from 'double (__cdecl *const )(int,double)' to 'const chaiscript::Proxy_Function &'   Chaiscript  c:\users\kung\documents\visual studio 2015\projects\chaiscript\chaiscript\language\chaiscript_engine.hpp    764 

The example code:

//main.cpp
#include "chaiscript/chaiscript.hpp"

double function(int i, double j)
{
  return i * j;
}

int main()
{
  chaiscript::ChaiScript chai;
  chai.add(&function, "function");

  double d = chai.eval<double>("function(3, 4.75);");
} 
kungfooman
  • 4,473
  • 1
  • 44
  • 33

1 Answers1

2

You are missing the chaiscript::fun() call in your test.

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

I strongly suggest you start with the complete example provided on the examples page:

#include <chaiscript/chaiscript.hpp>
#include <chaiscript/chaiscript_stdlib.hpp>

std::string helloWorld(const std::string &t_name)
{
  return "Hello " + t_name + "!";
}

int main()
{
  chaiscript::ChaiScript chai(chaiscript::Std_Lib::library());
  chai.add(chaiscript::fun(&helloWorld), "helloWorld");

  chai.eval("puts(helloWorld(\"Bob\"));");
}

Otherwise you'll quickly run into another error when you wonder why it cannot find the standard library.

lefticus
  • 3,346
  • 2
  • 24
  • 28