Skip to content

Instantly share code, notes, and snippets.

@lucidguppy
Created August 17, 2014 18:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucidguppy/c8917a8d73cacfae3c91 to your computer and use it in GitHub Desktop.
Save lucidguppy/c8917a8d73cacfae3c91 to your computer and use it in GitHub Desktop.
Create a chaiscript shared module and use it in the chaiscript repl
cmake_minimum_required (VERSION 2.8)
add_definitions(-std=c++11)
project (ChaiTutorial)
add_library(myModule SHARED myModule.cpp)
list(APPEND LIBS ${READLINE_LIB})
include_directories(/usr/local/include)
install(TARGETS myModule DESTINATION /usr/local/lib/chaiscript)
mkdir build
cd build
cmake ../
make
make install
chai testModule.chai
#include <chaiscript/chaiscript.hpp>
#include <string>
std::string helloWorld()
{
return "Hello World";
}
int addTwoNumbers(int a, int b)
{
return a + b;
}
CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_myModule()
{
chaiscript::ModulePtr m(new chaiscript::Module());
m->add(chaiscript::fun(helloWorld), "helloWorld");
m->add(chaiscript::fun(addTwoNumbers), "addTwoNumbers");
return m;
}
load_module("myModule");
print(helloWorld());
var x = addTwoNumbers(3,5);
print("The value of x is " + x.to_string());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment