Skip to content

Commit

Permalink
libstd/core: Added std::core::execute_function
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Jun 24, 2024
1 parent 371fe6f commit c70107c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/source/pl/lib/std/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ namespace pl::lib::libstd::core {

return false;
});

/* execute_function(function_name, args...) -> bool */
runtime.addDangerousFunction(nsStdCore, "execute_function", FunctionParameterCount::atLeast(1), [](Evaluator *evaluator, auto params) -> std::optional<Token::Literal> {
auto functionName = params[0].toString();

auto function = evaluator->findFunction(functionName);
if (!function.has_value()) {
err::E0009.throwError(fmt::format("Function '{}' does not exist.", functionName), {});
}

std::vector<pl::core::Token::Literal> functionParams;
for (size_t i = 1; i < params.size(); i += 1)
functionParams.emplace_back(std::move(params[i]));

return function.value().func(evaluator, functionParams);
});
}
}

Expand Down

0 comments on commit c70107c

Please sign in to comment.