Skip to content

Commit

Permalink
Reflect invocation function on standard library.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Oct 31, 2024
1 parent f25b348 commit 02dc7f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/zhvlib/Reflect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,33 @@ ZHIVO_FUNC(reflect_delete) {

return DynamicObject();
}

ZHIVO_FUNC(reflect_invoke) {
if(args.size() != 2)
throw TerminativeThrowSignal(
std::move(address),
"Expecting 2 argument, got " +
std::to_string(args.size())
);

DynamicObject name = args.at(0),
params = args.at(1);

if(!params.isArray())
throw TerminativeThrowSignal(
std::move(address),
"Parameters must be of array type"
);

const std::string symName = name.toString();
DynamicObject callable = symtab.getSymbol(
std::move(address),
symName
);

return callable.callFromNative(
std::move(address),
symtab,
*params.getArray()
);
}
1 change: 1 addition & 0 deletions lib/zhvlib/Reflect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ZHIVO_FUNC(reflect_type);

ZHIVO_FUNC(reflect_declare);
ZHIVO_FUNC(reflect_delete);
ZHIVO_FUNC(reflect_invoke);

ZHIVO_LIB_END

Expand Down

0 comments on commit 02dc7f5

Please sign in to comment.