include/static/unoembindhelpers/PrimaryBindings.hxx | 16 +++++ static/source/embindmaker/embindmaker.cxx | 47 ++++++++++++++++ static/source/unoembindhelpers/PrimaryBindings.cxx | 56 ++++++++++++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-)
New commits: commit e4cf6c324cd7491444576ee57d60475d0c4f239c Author: Stephan Bergmann <stephan.bergm...@allotropia.de> AuthorDate: Tue Jan 30 22:30:13 2024 +0100 Commit: Stephan Bergmann <stephan.bergm...@allotropia.de> CommitDate: Wed Jan 31 09:33:11 2024 +0100 Embind in-out/out params of primitive type apparently need a wrapper > let translit = css.i18n.Transliteration.create(Module.getUnoComponentContext()); > let match1; > let match2; > let eq = translit.equals(new Module.OUString("test1"), 0, 5, match1, new Module.OUString("test2"), 0, 5, match2); > console.log('match ' + eq + ', ' + match1 + ', ' + match2); caused an uncaught UnboundTypeError with message "Cannot call uno_Type_com$sun$star$i18n$XTransliteration.equals due to unbound types: Pl", so use > let translit = css.i18n.Transliteration.create(Module.getUnoComponentContext()); > let match1 = new Module.UnoInOutParamLong; > let match2 = new Module.UnoInOutParamLong; > let eq = translit.equals(new Module.OUString("test1"), 0, 5, match1, new Module.OUString("test2"), 0, 5, match2); > console.log('match ' + eq + ', ' + match1.val + ', ' + match2.val); > delete match1; > delete match2; instead Change-Id: Ic5a0a9e37e884817158069702510eab0d29adefa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162784 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de> diff --git a/include/static/unoembindhelpers/PrimaryBindings.hxx b/include/static/unoembindhelpers/PrimaryBindings.hxx index 0c744502848e..5b677345b86b 100644 --- a/include/static/unoembindhelpers/PrimaryBindings.hxx +++ b/include/static/unoembindhelpers/PrimaryBindings.hxx @@ -32,6 +32,22 @@ enum class uno_Reference { FromAny }; + +template <typename T> struct UnoInOutParam +{ + UnoInOutParam() {} + + UnoInOutParam(T the_value) + : value(the_value) + { + } + + T get() const { return value; } + + void set(T the_value) { value = the_value; } + + T value; +}; } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/static/source/embindmaker/embindmaker.cxx b/static/source/embindmaker/embindmaker.cxx index 6a9083f28516..cb0ad6c04445 100644 --- a/static/source/embindmaker/embindmaker.cxx +++ b/static/source/embindmaker/embindmaker.cxx @@ -444,9 +444,49 @@ void dumpParameters(std::ostream& out, rtl::Reference<TypeManager> const& manage { out << ", "; } + bool wrap = false; + if (param.direction != unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN) + { + switch (manager->getSort(resolveOuterTypedefs(manager, param.type))) + { + case codemaker::UnoType::Sort::Boolean: + case codemaker::UnoType::Sort::Byte: + case codemaker::UnoType::Sort::Short: + case codemaker::UnoType::Sort::UnsignedShort: + case codemaker::UnoType::Sort::Long: + case codemaker::UnoType::Sort::UnsignedLong: + case codemaker::UnoType::Sort::Hyper: + case codemaker::UnoType::Sort::UnsignedHyper: + case codemaker::UnoType::Sort::Float: + case codemaker::UnoType::Sort::Double: + case codemaker::UnoType::Sort::Char: + case codemaker::UnoType::Sort::Enum: + wrap = true; + break; + case codemaker::UnoType::Sort::String: + case codemaker::UnoType::Sort::Type: + case codemaker::UnoType::Sort::Any: + case codemaker::UnoType::Sort::Sequence: + case codemaker::UnoType::Sort::PlainStruct: + case codemaker::UnoType::Sort::InstantiatedPolymorphicStruct: + case codemaker::UnoType::Sort::Interface: + break; + default: + throw CannotDumpException("unexpected entity \"" + param.type + + "\" as parameter type"); + } + } if (declarations) { + if (wrap) + { + out << "::unoembindhelpers::UnoInOutParam<"; + } dumpType(out, manager, param.type); + if (wrap) + { + out << ">"; + } if (param.direction == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN) { if (passByReference(manager, param.type)) @@ -460,11 +500,16 @@ void dumpParameters(std::ostream& out, rtl::Reference<TypeManager> const& manage } out << " "; } - else if (param.direction != unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN) + else if (param.direction != unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN + && !wrap) { out << "*"; } out << param.name; + if (!declarations && wrap) + { + out << "->value"; + } } } diff --git a/static/source/unoembindhelpers/PrimaryBindings.cxx b/static/source/unoembindhelpers/PrimaryBindings.cxx index 4277af563936..0a87d32e2710 100644 --- a/static/source/unoembindhelpers/PrimaryBindings.cxx +++ b/static/source/unoembindhelpers/PrimaryBindings.cxx @@ -111,6 +111,62 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings) }, allow_raw_pointers()); + class_<unoembindhelpers::UnoInOutParam<bool>>("UnoInOutParamBoolean") + .constructor() + .constructor<bool>() + .property("val", &unoembindhelpers::UnoInOutParam<bool>::get, + &unoembindhelpers::UnoInOutParam<bool>::set); + class_<unoembindhelpers::UnoInOutParam<sal_Int8>>("UnoInOutParamByte") + .constructor() + .constructor<sal_Int8>() + .property("val", &unoembindhelpers::UnoInOutParam<sal_Int8>::get, + &unoembindhelpers::UnoInOutParam<sal_Int8>::set); + class_<unoembindhelpers::UnoInOutParam<sal_Int16>>("UnoInOutParamShort") + .constructor() + .constructor<sal_Int16>() + .property("val", &unoembindhelpers::UnoInOutParam<sal_Int16>::get, + &unoembindhelpers::UnoInOutParam<sal_Int16>::set); + class_<unoembindhelpers::UnoInOutParam<sal_uInt16>>("UnoInOutParamUnsignedShort") + .constructor() + .constructor<sal_uInt16>() + .property("val", &unoembindhelpers::UnoInOutParam<sal_uInt16>::get, + &unoembindhelpers::UnoInOutParam<sal_uInt16>::set); + class_<unoembindhelpers::UnoInOutParam<sal_Int32>>("UnoInOutParamLong") + .constructor() + .constructor<sal_Int32>() + .property("val", &unoembindhelpers::UnoInOutParam<sal_Int32>::get, + &unoembindhelpers::UnoInOutParam<sal_Int32>::set); + class_<unoembindhelpers::UnoInOutParam<sal_uInt32>>("UnoInOutParamUnsignedLong") + .constructor() + .constructor<sal_uInt32>() + .property("val", &unoembindhelpers::UnoInOutParam<sal_uInt32>::get, + &unoembindhelpers::UnoInOutParam<sal_uInt32>::set); + class_<unoembindhelpers::UnoInOutParam<sal_Int64>>("UnoInOutParamHyper") + .constructor() + .constructor<sal_Int64>() + .property("val", &unoembindhelpers::UnoInOutParam<sal_Int64>::get, + &unoembindhelpers::UnoInOutParam<sal_Int64>::set); + class_<unoembindhelpers::UnoInOutParam<sal_uInt64>>("UnoInOutParamUnsignedHyper") + .constructor() + .constructor<sal_uInt64>() + .property("val", &unoembindhelpers::UnoInOutParam<sal_uInt64>::get, + &unoembindhelpers::UnoInOutParam<sal_uInt64>::set); + class_<unoembindhelpers::UnoInOutParam<float>>("UnoInOutParamFloat") + .constructor() + .constructor<float>() + .property("val", &unoembindhelpers::UnoInOutParam<float>::get, + &unoembindhelpers::UnoInOutParam<float>::set); + class_<unoembindhelpers::UnoInOutParam<double>>("UnoInOutParamDouble") + .constructor() + .constructor<double>() + .property("val", &unoembindhelpers::UnoInOutParam<double>::get, + &unoembindhelpers::UnoInOutParam<double>::set); + class_<unoembindhelpers::UnoInOutParam<char16_t>>("UnoInOutParamChar") + .constructor() + .constructor<char16_t>() + .property("val", &unoembindhelpers::UnoInOutParam<char16_t>::get, + &unoembindhelpers::UnoInOutParam<char16_t>::set); + function("getCurrentModelFromViewSh", &getCurrentModelFromViewSh); function("getUnoComponentContext", &comphelper::getProcessComponentContext); }