Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wibbe/scheme-cpp
A lightweight wrapper around TinyScheme
https://github.com/wibbe/scheme-cpp
Last synced: 18 days ago
JSON representation
A lightweight wrapper around TinyScheme
- Host: GitHub
- URL: https://github.com/wibbe/scheme-cpp
- Owner: wibbe
- License: mit
- Created: 2011-03-02T20:50:41.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-03-06T18:17:47.000Z (over 13 years ago)
- Last Synced: 2024-07-31T22:58:01.498Z (3 months ago)
- Language: C
- Homepage:
- Size: 195 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.textile
- License: LICENSE
Awesome Lists containing this project
README
h1. Scheme-Cpp
A lightweight C++ wrapper around TinyScheme (http://tinyscheme.sourceforge.net/home.html)
h2. Building
OS X and Linux is the only supported platforms for the moment, and you will need CMake to generate the required Makefile.
Create a build folder, this step is optional, but it's encouraged. It makes cleaning up a lot easier, especially because CMake creates a lot of files all over the place:
@mkdir build@
@cd build@Generate makefiles for the project:
@cmake -DCMAKE_BUILD_TYPE=Debug ..@Compile:
@make@h2. Example
A simple example on how to use the library.
Start by creating an instance of the Interpreter.
bc. script::Interpreter eval;
Next we can execute some code, here we define a function called add.
bc. eval.loadScript("(define (add a b) (+ a b))");
Then we can call our new function, and get back the result.
bc. script::Cell result = eval.call("add", 1, 2);
And lastly we can access the result.
bc. int value = result.toInteger();
h3. Binding C functions
It is really easy to bind C functions so they can be accessed from scheme.
First we define out function, lets make a print function.
bc. void printFunc(std::string const& str)
{
std::cout << str << std::endl;
}Then we create an interpreter and bind our function to it.
bc. script::Interpreter eval;
eval.function("print", printFunc);We can then call our C function from scheme.
bc. eval.loadString("(print \"Hello World!\")");
h2. License
See the LICENSE file for legal information about Scheme-Cpp. For license information about
TinyScheme see the file @src/tinyscheme/COPYING@.