Created
August 17, 2014 18:20
-
-
Save lucidguppy/c8917a8d73cacfae3c91 to your computer and use it in GitHub Desktop.
Create a chaiscript shared module and use it in the chaiscript repl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir build | |
cd build | |
cmake ../ | |
make | |
make install | |
chai testModule.chai |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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