Switch get_function to default to not doing object lookup. Correct method eval to maintain method lambda syntax. Add unit test for method lambda
This commit is contained in:
@@ -324,7 +324,7 @@ namespace chaiscript
|
||||
std::vector<std::pair<std::string, std::multimap<std::string, Proxy_Function >::mapped_type> >
|
||||
get_function(const std::string &t_name) const
|
||||
{
|
||||
return get_function_impl(t_name, true);
|
||||
return get_function_impl(t_name, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -471,23 +471,32 @@ namespace chaiscript
|
||||
}
|
||||
}
|
||||
|
||||
std::string fun_name;
|
||||
if (node->children[i]->identifier == Token_Type::Fun_Call) {
|
||||
fun_name = node->children[i]->children[0]->text;
|
||||
}
|
||||
else {
|
||||
fun_name = node->children[i]->text;
|
||||
}
|
||||
|
||||
//std::string fun_name;
|
||||
Boxed_Value fn;
|
||||
try {
|
||||
fn = ss.get_function(fun_name);
|
||||
if (node->children[i]->identifier == Token_Type::Fun_Call) {
|
||||
//fun_name = node->children[i]->children[0]->text;
|
||||
fn = eval_token(ss, node->children[i]->children[0]);
|
||||
}
|
||||
else {
|
||||
//fun_name = node->children[i]->text;
|
||||
fn = eval_token(ss, node->children[i]);
|
||||
}
|
||||
}
|
||||
catch(Eval_Error &ee) {
|
||||
ss.set_stack(prev_stack);
|
||||
throw Eval_Error(ee.reason, node->children[i]);
|
||||
}
|
||||
try {
|
||||
//fn = ss.get_function(fun_name);
|
||||
ss.set_stack(new_stack);
|
||||
retval = dispatch(fn, plb);
|
||||
//retval = dispatch(fn, plb);
|
||||
retval = (*boxed_cast<Proxy_Function >(fn))(plb);
|
||||
ss.set_stack(prev_stack);
|
||||
}
|
||||
catch(const dispatch_error &e){
|
||||
ss.set_stack(prev_stack);
|
||||
throw Eval_Error(std::string(e.what()) + " with function '" + fun_name + "'", node->children[i]);
|
||||
throw Eval_Error(std::string(e.what()), node->children[i]);
|
||||
}
|
||||
catch(Return_Value &rv) {
|
||||
ss.set_stack(prev_stack);
|
||||
|
3
unittests/method_lambda.chai
Normal file
3
unittests/method_lambda.chai
Normal file
@@ -0,0 +1,3 @@
|
||||
var addit = fun(x, y) { return x+y }
|
||||
|
||||
print(3.addit(4))
|
1
unittests/method_lambda.txt
Normal file
1
unittests/method_lambda.txt
Normal file
@@ -0,0 +1 @@
|
||||
7
|
Reference in New Issue
Block a user