MCPcopy Create free account
hub / github.com/MaaXYZ/MaaFramework / add_bind

Method add_bind

source/binding/NodeJS/src/apis/controller.cpp:787–816  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

785}
786
787void CustomControllerContext::add_bind(
788 maajs::EnvType env,
789 std::string name,
790 std::string func_name,
791 int argc,
792 std::shared_ptr<maajs::ObjectRefType> actor,
793 std::function<maajs::ValueType(maajs::EnvType)> fallback)
794{
795 callbacks[name] = new maajs::CallbackContext(
796 maajs::MakeFunction(
797 env,
798 func_name.c_str(),
799 argc,
800 [actor, name, fallback](const auto& info) -> maajs::ValueType {
801 auto func = actor->Value()[name].AsValue();
802 if (func.IsFunction()) {
803 std::vector<maajs::ValueType> args;
804 args.reserve(info.Length());
805 for (size_t i = 0; i < info.Length(); i++) {
806 args.push_back(info[i]);
807 }
808 return func.As<maajs::FunctionType>().Call(actor->Value(), args);
809 }
810 else {
811 return fallback(info.Env());
812 }
813 },
814 actor),
815 func_name.c_str());
816}
817
818void CustomControllerContext::gc_mark(maajs::NativeMarkerFunc marker)
819{

Callers 1

ctorMethod · 0.80

Calls 7

AsValueMethod · 0.80
IsFunctionMethod · 0.80
MakeFunctionFunction · 0.50
ValueMethod · 0.45
LengthMethod · 0.45
CallMethod · 0.45
EnvMethod · 0.45

Tested by

no test coverage detected