Skip to content

Instantly share code, notes, and snippets.

@lucidguppy
Created August 17, 2014 18:20

Revisions

  1. lucidguppy created this gist Aug 17, 2014.
    7 changes: 7 additions & 0 deletions CMakeLists.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    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)
    6 changes: 6 additions & 0 deletions command line
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    mkdir build
    cd build
    cmake ../
    make
    make install
    chai testModule.chai
    20 changes: 20 additions & 0 deletions myModule.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #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;
    }
    5 changes: 5 additions & 0 deletions testModule.chai
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    load_module("myModule");

    print(helloWorld());
    var x = addTwoNumbers(3,5);
    print("The value of x is " + x.to_string());