Skip to content

Commit

Permalink
Implement sass variable environment access
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Dec 7, 2016
1 parent 196fbd3 commit 2a3fa42
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
42 changes: 42 additions & 0 deletions Sass.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,48 @@ get_callee_column(back)
OUTPUT:
RETVAL

SV*
get_callee_var(name, back)
const char* name
size_t back
CODE:
{

SV* comp = get_sv("CSS::Sass::compiler", GV_ADDWARN);
struct Sass_Compiler* compiler = INT2PTR(struct Sass_Compiler*, SvIV(comp));
size_t idx = sass_compiler_get_callee_stack_size(compiler);
if (idx <= back) croak("Callee stack access out of boundary");
Sass_Callee_Entry entry = sass_compiler_get_callee_entry(compiler, idx - back - 1);
Sass_Env_Frame env = sass_callee_get_env(entry);
union Sass_Value* value = sass_env_get_lexical(env, name);
if (value == NULL) RETVAL = new_sv_sass_null();
else RETVAL = sass_value_to_sv(value);

}
OUTPUT:
RETVAL

SV*
set_callee_var(name, value, back)
const char* name
SV* value
size_t back
CODE:
{

SV* comp = get_sv("CSS::Sass::compiler", GV_ADDWARN);
struct Sass_Compiler* compiler = INT2PTR(struct Sass_Compiler*, SvIV(comp));
size_t idx = sass_compiler_get_callee_stack_size(compiler);
if (idx <= back) croak("Callee stack access out of boundary");
Sass_Callee_Entry entry = sass_compiler_get_callee_entry(compiler, idx - back - 1);
Sass_Env_Frame env = sass_callee_get_env(entry);
sass_env_set_lexical(env, name, sv_to_sass_value(value));
RETVAL = new_sv_sass_null();

}
OUTPUT:
RETVAL

SV*
libsass_version()
CODE:
Expand Down
4 changes: 3 additions & 1 deletion lib/CSS/Sass.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ our @EXPORT_OK = qw(
get_callee_path
get_callee_line
get_callee_column
get_callee_var
set_callee_var
get_import_abs_path
get_import_imp_path
get_import_stack_size
Expand Down Expand Up @@ -626,7 +628,7 @@ L<The CSS::Sass Home Page|https://github.com/sass/perl-libsass>
=head1 AUTHOR
David Caldwell E<lt>david@porkrind.orgE<gt>
David Caldwell E<lt>david@porkrind.orgE<gt>
Marcel Greter E<lt>perl-libsass@ocbnet.chE<gt>
=head1 LICENSE
Expand Down
2 changes: 1 addition & 1 deletion libsass

0 comments on commit 2a3fa42

Please sign in to comment.