From d3de95714fba7534bbc4fe07d5ab86a5b5e6b620 Mon Sep 17 00:00:00 2001 From: Marcel Greter Date: Thu, 12 Mar 2015 20:54:18 +0100 Subject: [PATCH] Add plugin.cpp example to contrib directory Additionally adds VERSION file to .gitignore --- .gitignore | 1 + contrib/plugin.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 contrib/plugin.cpp diff --git a/.gitignore b/.gitignore index f6fb025b5c..d36d048fd0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Miscellaneous stuff +VERSION .DS_Store .sass-cache *.gem diff --git a/contrib/plugin.cpp b/contrib/plugin.cpp new file mode 100644 index 0000000000..8d154f1936 --- /dev/null +++ b/contrib/plugin.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include "sass_values.h" + +// gcc: g++ -shared plugin.cpp -o plugin.so -fPIC -Llib -lsass +// mingw: g++ -shared plugin.cpp -o plugin.dll -Llib -lsass + +union Sass_Value* call_fn_foo(const union Sass_Value* s_args, void* cookie) +{ + // we actually abuse the void* to store an "int" + return sass_make_number((intptr_t)cookie, "px"); +} + +extern "C" const char* ADDCALL libsass_get_version() { + return libsass_version(); +} + +extern "C" Sass_C_Function_List ADDCALL libsass_load_functions() +{ + // allocate a custom function caller + Sass_C_Function_Callback fn_foo = + sass_make_function("foo()", call_fn_foo, (void*)42); + // create list of all custom functions + Sass_C_Function_List fn_list = sass_make_function_list(1); + // put the only function in this plugin to the list + sass_function_set_list_entry(fn_list, 0, fn_foo); + // return the list + return fn_list; +}