Skip to content

Commit

Permalink
Merge pull request sass#710 from mgreter/feature/default-args-cust-fn
Browse files Browse the repository at this point in the history
Fix default argument passing for custom c functions
  • Loading branch information
mgreter committed Dec 13, 2014
2 parents fbbfc87 + 0b46257 commit 6173d61
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,24 +423,30 @@ namespace Sass {
// else if it's a user-defined c function
else if (c_func) {

if (full_name != "*[f]") {
bind("function " + c->name(), params, args, ctx, &new_env, this);
} else {
if (full_name == "*[f]") {
String_Constant *str = new (ctx.mem) String_Constant(c->path(), c->position(), c->name());
Arguments* new_args = new (ctx.mem) Arguments(c->path(), c->position());
*new_args << new (ctx.mem) Argument(c->path(), c->position(), str);
*new_args += args;
args = new_args;
}

// populates env with default values for params
bind("function " + c->name(), params, args, ctx, &new_env, this);
Env* old_env = env;
env = &new_env;

Backtrace here(backtrace, c->path(), c->position(), ", in function `" + c->name() + "`");
backtrace = &here;

To_C to_c;
union Sass_Value* c_args = args->perform(&to_c);
union Sass_Value* c_args = sass_make_list(env->current_frame().size(), SASS_COMMA);
for(size_t i = 0; i < params[0].length(); i++) {
string key = params[0][i]->name();
AST_Node* node = env->current_frame().at(key);
Expression* arg = static_cast<Expression*>(node);
sass_list_set_value(c_args, i, arg->perform(&to_c));
}
Sass_Value* c_val = c_func(c_args, def->cookie());
if (sass_value_get_tag(c_val) == SASS_ERROR) {
error("error in C function " + c->name() + ": " + sass_error_get_message(c_val), c->path(), c->position(), backtrace);
Expand Down

0 comments on commit 6173d61

Please sign in to comment.