-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add plugin.cpp example to contrib directory
Additionally adds VERSION file to .gitignore
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Miscellaneous stuff | ||
|
||
VERSION | ||
.DS_Store | ||
.sass-cache | ||
*.gem | ||
|
This file contains 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
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; | ||
} |