Skip to content

Commit

Permalink
Added an index FFL function. It takes a list and value as arguments a…
Browse files Browse the repository at this point in the history
…nd returns the index of the value in the list, -1 if it wasn't found in the list.
  • Loading branch information
sweetkristas committed Jul 1, 2012
1 parent bd52d21 commit 6d4b3d8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/formula_function.cpp
Expand Up @@ -1207,6 +1207,17 @@ FUNCTION_DEF(show_modal, 1, 1, "show_modal(dialog): Displays a modal dialog on t
return variant::from_bool(dialog->cancelled() == false);
END_FUNCTION_DEF(show_modal)

FUNCTION_DEF(index, 2, 2, "index(list, value) -> index of value in list: Returns the index of the value in the list or -1 if value wasn't found in the list.")
variant value = args()[1]->evaluate(variables);
variant li = args()[0]->evaluate(variables);
for(int n = 0; n < li.num_elements(); n++) {
if(value == li[n]) {
return variant(n);
}
}
return variant(-1);
END_FUNCTION_DEF(index)

namespace {
void evaluate_expr_for_benchmark(const formula_expression* expr, const formula_callable* variables, int ntimes)
{
Expand Down

0 comments on commit 6d4b3d8

Please sign in to comment.