Skip to content

Commit

Permalink
Add plugin.cpp example to contrib directory
Browse files Browse the repository at this point in the history
Additionally adds VERSION file to .gitignore
  • Loading branch information
mgreter committed Mar 12, 2015
1 parent 3529e2a commit d3de957
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Miscellaneous stuff

VERSION
.DS_Store
.sass-cache
*.gem
Expand Down
30 changes: 30 additions & 0 deletions contrib/plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <cstring>
#include <iostream>
#include <stdint.h>
#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;
}

0 comments on commit d3de957

Please sign in to comment.